sctp: Defer SCTP_DBG_OBJCNT_DEC() to sctp_destroy_sock().
[ Upstream commit622e8838a2] SCTP_DBG_OBJCNT_INC() is called only when sctp_init_sock() returns 0 after successfully allocating sctp_sk(sk)->ep. OTOH, SCTP_DBG_OBJCNT_DEC() is called in sctp_close(). The code seems to expect that the socket is always exposed to userspace once SCTP_DBG_OBJCNT_INC() is incremented, but there is a path where the assumption is not true. In sctp_accept(), sctp_sock_migrate() could fail after sctp_init_sock(). Then, sk_common_release() does not call inet_release() nor sctp_close(). Instead, it calls sk->sk_prot->destroy(). Let's move SCTP_DBG_OBJCNT_DEC() from sctp_close() to sctp_destroy_sock(). Fixes:1da177e4c3("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com> Acked-by: Xin Long <lucien.xin@gmail.com> Link: https://patch.msgid.link/20251023231751.4168390-2-kuniyu@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
93105c6a52
commit
db83a538ff
@@ -1552,8 +1552,6 @@ static void sctp_close(struct sock *sk, long timeout)
|
||||
spin_unlock_bh(&net->sctp.addr_wq_lock);
|
||||
|
||||
sock_put(sk);
|
||||
|
||||
SCTP_DBG_OBJCNT_DEC(sock);
|
||||
}
|
||||
|
||||
/* Handle EPIPE error. */
|
||||
@@ -5105,9 +5103,12 @@ static void sctp_destroy_sock(struct sock *sk)
|
||||
sp->do_auto_asconf = 0;
|
||||
list_del(&sp->auto_asconf_list);
|
||||
}
|
||||
|
||||
sctp_endpoint_free(sp->ep);
|
||||
|
||||
sk_sockets_allocated_dec(sk);
|
||||
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
|
||||
SCTP_DBG_OBJCNT_DEC(sock);
|
||||
}
|
||||
|
||||
/* Triggered when there are no references on the socket anymore */
|
||||
|
||||
Reference in New Issue
Block a user