Re: [PATCH net] sctp: fix sockets_allocated imbalance after sk_clone()

Kuniyuki Iwashima <[email protected]> Sun, 19 Apr 2026 17:38:30 -0700
Newsgroups org.kernel.vger.linux-sctp,org.kernel.vger.netdev
Message-ID <CAAVpQUCdXJS_VNNjtq_oiygaMJiFMoaJ2kynRR+aEu=-3aahqQ@mail.gmail.com>
On Fri, Apr 17, 2026 at 2:09 PM Xin Long <[email protected]> wrote:
>
> 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: 16942cf4d3e3 ("sctp: Use sk_clone() in sctp_accept().")
> Signed-off-by: Xin Long <[email protected]>

Thanks for the fix.

Reviewed-by: Kuniyuki Iwashima <[email protected]>

I fixed a similar one in 622e8838a298.  We may want to
perform inc/dec regardless of sp->ep and simplify the code
once net-next opens.