From: Paolo Abeni <pabeni@redhat.com>
To: Kenny Hsieh <kenny_hsieh@jabil.com>,
netdev@vger.kernel.org, Jeremy Kerr <jk@codeconstruct.com.au>,
Matt Johnston <matt@codeconstruct.com.au>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
stable@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v5] mctp i2c: fix double free of midev on netdev register failure
Date: Thu, 3 Dec 2026 11:22:04 +0100 [thread overview]
Message-ID: <1e1e6dd1-99d7-4d97-8858-977d73adeadd@redhat.com> (raw)
In-Reply-To: <20261124101237.3884438-1-kenny_hsieh@jabil.com>
On 11/24/26 11:12, Kenny Hsieh wrote:
> mctp_i2c_add_netdev() frees midev if mctp_register_netdev() fails, but
> 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@codeconstruct.com.au>
> Fixes: f5b8abf9fc3d ("mctp i2c: MCTP I2C binding driver")
> Closes: https://lore.kernel.org/netdev/179239912623.3135.11352652156626817288@kernel.org/
> Cc: stable@vger.kernel.org
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Kenny Hsieh <kenny_hsieh@jabil.com>
FYI, day-1, sashiko driven issues, at device reg/unreg time are not
net material.
/P
next prev parent reply other threads:[~2026-12-03 10:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 10:12 [PATCH net v5] mctp i2c: fix double free of midev on netdev register failure Kenny Hsieh
2026-12-03 10:22 ` Paolo Abeni [this message]
2026-12-03 10:30 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1e1e6dd1-99d7-4d97-8858-977d73adeadd@redhat.com \
--to=pabeni@redhat.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=jk@codeconstruct.com.au \
--cc=kenny_hsieh@jabil.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matt@codeconstruct.com.au \
--cc=netdev@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox