Skip to content

Commit ead5565

Browse files
kcp-gitgerd-rausch
authored andcommitted
rds: Incorrect reference counting in TCP socket creation
Commit ed8b4f1 ("rds: tcp: use sock_create_lite() to create the accept socket") has a reference counting issue in TCP socket creation when accepting a new connection. The code uses sock_create_lite() to create a kernel socket. But it does not do __module_get() on the socket owner. When the connection is shutdown and sock_release() is called to free the socket, the owner's reference count is decremented and becomes incorrect. Note that this bug only shows up when IPv6 is configured as a kernel module. Orabug: 27493581 Signed-off-by: Ka-Cheong Poon <[email protected]> Reviewed-by: Håkon Bugge <[email protected]> Signed-off-by: Somasundaram Krishnasamy <[email protected]>
1 parent 6321891 commit ead5565

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

net/rds/tcp_listen.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006, 2017 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This software is available to you under a choice of one of two
55
* licenses. You may choose to be licensed under the terms of the GNU
@@ -132,12 +132,17 @@ int rds_tcp_accept_one(struct socket *sock)
132132
if (ret)
133133
goto out;
134134

135-
new_sock->type = sock->type;
136-
new_sock->ops = sock->ops;
137135
ret = sock->ops->accept(sock, new_sock, O_NONBLOCK, true);
138136
if (ret < 0)
139137
goto out;
140138

139+
new_sock->ops = sock->ops;
140+
/* sock_create_lite() does not get a hold on the owner module so we
141+
* need to do it here. No need to do try_module_get() as the listener
142+
* should have a hold already.
143+
*/
144+
__module_get(new_sock->ops->owner);
145+
141146
ret = rds_tcp_keepalive(new_sock);
142147
if (ret < 0)
143148
goto out;

0 commit comments

Comments
 (0)