Skip to content

Commit 7c9b012

Browse files
lxinkuba-moo
authored andcommitted
sctp: fix sockets_allocated imbalance after sk_clone()
sk_clone() increments sockets_allocated and sets the socket refcount to 2. SCTP performs additional accounting in sctp_clone_sock(), so the clone-time increment must be undone to avoid double counting. Note we cannot simply remove the SCTP-side increment, because the SCTP destroy path in sctp_destroy_sock() only decrements sockets_allocated when sp->ep is set, which may not be true for all failure paths in sctp_clone_sock(). Fixes: 16942cf ("sctp: Use sk_clone() in sctp_accept().") Signed-off-by: Xin Long <lucien.xin@gmail.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com> Link: https://patch.msgid.link/af8d66f928dec3e9fcbee8d4a85b7d5a6b86f515.1776460180.git.lucien.xin@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 0db1688 commit 7c9b012

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

net/sctp/socket.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4855,8 +4855,9 @@ static struct sock *sctp_clone_sock(struct sock *sk,
48554855
if (!newsk)
48564856
return ERR_PTR(err);
48574857

4858-
/* sk_clone() sets refcnt to 2 */
4858+
/* sk_clone() sets refcnt to 2 and increments sockets_allocated */
48594859
sock_put(newsk);
4860+
sk_sockets_allocated_dec(newsk);
48604861

48614862
newinet = inet_sk(newsk);
48624863
newsp = sctp_sk(newsk);

0 commit comments

Comments
 (0)