Re: [PATCH net v4 1/3] netconsole: finish enabling the target before releasing RTNL

From: Breno Leitao

Date: Mon Oct 26 2026 - 08:04:12 EST


On Wed, Oct 21, 2026 at 03:19:05PM +0100, Gustavo Luiz Duarte wrote:
> netcons_netpoll_setup() publishes nt->np.dev inside __netpoll_setup(),
> then releases the RTNL and waits for an RCU grace period before
> returning. Only after that does its caller store STATE_ENABLED.
>
> A NETDEV_UNREGISTER event landing in that window tears the target down
> and we end up storing STATE_ENABLED with a NULL np->dev, leading to a
> null-ptr-deref in netconsole_write():
>
> BUG: KASAN: null-ptr-deref in netconsole_write+0xb9/0x7f0
> Read of size 8 at addr 00000000000000a8 by task pr/netcon_ext0/135
> netconsole_write+0xb9/0x7f0
> nbcon_emit_next_record+0x501/0x550
> nbcon_emit_one+0x10e/0x170
> nbcon_kthread_func+0x2ff/0x3b0
> kthread+0x199/0x1e0
>
> Store STATE_ENABLED before dropping the RTNL lock to avoid racing with
> netconsole_netdev_event().
>
> Fixes: 2382b15bcc39 ("netconsole: take care of NETDEV_UNREGISTER event")
> Signed-off-by: Gustavo Luiz Duarte <gustavold@xxxxxxxxx>

Reviewed-by: Breno Leitao <leitao@xxxxxxxxxx>