* [PATCH net v2] netdevsim: take bus device refcount before registering device
@ 2026-09-02 2:57 Adriano Cordova
2026-09-04 0:10 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Adriano Cordova @ 2026-09-02 2:57 UTC (permalink / raw)
To: Jakub Kicinski, netdev
Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Paolo Abeni,
linux-kernel, Adriano Cordova, syzbot+989ff6506f5c6d1ff56b
nsim_bus_dev_release() drops nsim_bus_devs when a device is freed, but
the matching increment was done in new_device_store() after
nsim_bus_dev_new() returned. When device_register() failed inside
nsim_bus_dev_new(), put_device() invoked the release callback and
decremented without an increment, driving the refcount to zero; a later
creation then incremented from zero (refcount_t: addition on 0).
Increment nsim_bus_devs in nsim_bus_dev_new() before device_register(),
and drop the bus reference in nsim_bus_exit() only after every device has
been removed, so the completion cannot be signaled early.
Reported-by: syzbot+989ff6506f5c6d1ff56b@syzkaller.appspot.com
Closes: https://syzkaller.appspot.com/bug?extid=989ff6506f5c6d1ff56b
Fixes: 6aff7cbfe7bfa ("netdevsim: Block until all devices are released")
Signed-off-by: Adriano Cordova <adrianox@gmail.com>
---
v2: https://lore.kernel.org/netdev/20260831183952.1345042-1-adrianox@gmail.com/
- also drop the bus reference in nsim_bus_exit() only after all
devices have been removed, per Jakub Kicinski, so that
wait_for_completion() cannot be signaled early
drivers/net/netdevsim/bus.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c
index 5c55c308487b..b792ee10b1c1 100644
--- a/drivers/net/netdevsim/bus.c
+++ b/drivers/net/netdevsim/bus.c
@@ -194,7 +194,6 @@ new_device_store(const struct bus_type *bus, const char *buf, size_t count)
goto err;
}
- refcount_inc(&nsim_bus_devs);
/* Allow using nsim_bus_dev */
smp_store_release(&nsim_bus_dev->init, true);
@@ -465,6 +464,7 @@ nsim_bus_dev_new(unsigned int id, unsigned int port_count, unsigned int num_queu
/* Disallow using nsim_bus_dev */
smp_store_release(&nsim_bus_dev->init, false);
+ refcount_inc(&nsim_bus_devs);
err = device_register(&nsim_bus_dev->dev);
if (err)
goto err_nsim_bus_dev_id_free;
@@ -520,8 +520,6 @@ void nsim_bus_exit(void)
/* Disallow using resources */
smp_store_release(&nsim_bus_enable, false);
- if (refcount_dec_and_test(&nsim_bus_devs))
- complete(&nsim_bus_devs_released);
mutex_lock(&nsim_bus_dev_list_lock);
list_for_each_entry_safe(nsim_bus_dev, tmp, &nsim_bus_dev_list, list) {
@@ -530,6 +528,9 @@ void nsim_bus_exit(void)
}
mutex_unlock(&nsim_bus_dev_list_lock);
+ if (refcount_dec_and_test(&nsim_bus_devs))
+ complete(&nsim_bus_devs_released);
+
wait_for_completion(&nsim_bus_devs_released);
driver_unregister(&nsim_driver);
--
2.51.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net v2] netdevsim: take bus device refcount before registering device
2026-09-02 2:57 [PATCH net v2] netdevsim: take bus device refcount before registering device Adriano Cordova
@ 2026-09-04 0:10 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-09-04 0:10 UTC (permalink / raw)
To: Adriano Cordova
Cc: kuba, netdev, andrew+netdev, davem, edumazet, pabeni,
linux-kernel, syzbot+989ff6506f5c6d1ff56b
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Tue, 1 Sep 2026 22:57:04 -0400 you wrote:
> nsim_bus_dev_release() drops nsim_bus_devs when a device is freed, but
> the matching increment was done in new_device_store() after
> nsim_bus_dev_new() returned. When device_register() failed inside
> nsim_bus_dev_new(), put_device() invoked the release callback and
> decremented without an increment, driving the refcount to zero; a later
> creation then incremented from zero (refcount_t: addition on 0).
>
> [...]
Here is the summary with links:
- [net,v2] netdevsim: take bus device refcount before registering device
https://git.kernel.org/netdev/net-next/c/d5f5853f167f
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-04 0:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-02 2:57 [PATCH net v2] netdevsim: take bus device refcount before registering device Adriano Cordova
2026-09-04 0:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox