Re: [PATCH net v5] mctp i2c: fix double free of midev on netdev register failure
From: Paolo Abeni
Date: Thu Dec 03 2026 - 05:22:15 EST
On 11/24/26 11:12, Kenny Hsieh wrote:
mctp_i2c_add_netdev() frees midev if mctp_register_netdev() fails, butFYI, day-1, sashiko driven issues, at device reg/unreg time are not
register_netdevice() may already have freed it through ndo_uninit,
mctp_i2c_ndo_uninit(). midev is then freed twice: list_del() runs on a
poisoned entry, and the adapter and client lose a second reference.
Free midev only where it was set up: in the add_netdev() error path,
and in mctp_i2c_unregister() before free_netdev().
ndo_uninit no longer frees midev. It still stops the tx thread, drops
mcli->sel's reference and purges tx_queue before the core waits for
the last netdev reference, also when a NETDEV_REGISTER notifier
fails, and each step is safe to repeat.
Freeing after unregister exposes two more things the old order hid.
Flows released while the netdev unregisters queue the unlock marker,
which is embedded in midev and must not reach kfree_skb() through the
purge, so the purge takes the marker off and splices the queue out
under one hold of the queue lock. And the bus lock, an rt_mutex taken
by the tx thread, was released by whoever called kthread_stop(); the
tx thread now drops it itself before exiting.
The double free was pointed out by the Sashiko AI review of a pending
mctp-i2c change, as a problem that predates it. None of this was hit
on hardware: it takes a late register_netdevice() failure, or a flow
key race during unregister.
Suggested-by: Matt Johnston <matt@xxxxxxxxxxxxxxxxxxxx>
Fixes: f5b8abf9fc3d ("mctp i2c: MCTP I2C binding driver")
Closes: https://lore.kernel.org/netdev/179239912623.3135.11352652156626817288@xxxxxxxxxx/
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Kenny Hsieh <kenny_hsieh@xxxxxxxxx>
net material.
/P