Re: [PATCH net] net: mctp: don't hold a zero-refcount socket in mctp_key_alloc()

From: Jeremy Kerr

Date: Fri Dec 04 2026 - 06:05:23 EST


Hi Andrew,

> From: Andrew Stellman <astellman@xxxxxxxxxxxxxxxxxxx>
>
> mctp_dst_input() finds the bound socket with mctp_lookup_bind() under
> RCU only, without holding a reference. If a concurrent close drops
> the last reference after that lookup, mctp_key_alloc() calls
> sock_hold() on a zero refcount, which saturates it and warns, and
> mctp_key_unref() later underflows it.
>
> Take the reference with refcount_inc_not_zero() and fail the key
> allocation if the socket is already at zero.

Looks good, thanks.

Reviewed-by: Jeremy Kerr <jk@xxxxxxxxxxxxxxxxxxxx>

> Tested on net-next 19c484e12ed2 (7.4.0-rc4) in arm64 QEMU with a
> private KUnit case

Can we have that too?

Cheers,


Jeremy