From: Jakub Kicinski <kuba@kernel.org>
To: Adriano Cordova <adrianox@gmail.com>
Cc: netdev@vger.kernel.org, Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
linux-kernel@vger.kernel.org,
syzbot+989ff6506f5c6d1ff56b@syzkaller.appspot.com
Subject: Re: [PATCH net] netdevsim: take bus device refcount before registering device
Date: Tue, 1 Sep 2026 17:06:26 -0700 [thread overview]
Message-ID: <20260901170626.6136cdf1@kernel.org> (raw)
In-Reply-To: <20260831183952.1345042-1-adrianox@gmail.com>
On Mon, 31 Aug 2026 14:39:52 -0400 Adriano Cordova wrote:
> nsim_bus_dev_release() drops nsim_bus_devs when a device is freed, but
> the matching increment was done in new_device_store() only after
> nsim_bus_dev_new() returned successfully. When device_register() failed
> inside nsim_bus_dev_new(), put_device() invoked the release callback and
> decremented nsim_bus_devs without the increment, driving the refcount to
> zero. A later successful device creation then incremented from zero and
> triggered:
>
> refcount_t: addition on 0; use-after-free.
>
> Increment nsim_bus_devs in nsim_bus_dev_new() before device_register() so
> the release callback's decrement is balanced on both the success and error
> paths.
This is still racy, please squash this into v2:
@@ -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);
--
pw-bot: cr
prev parent reply other threads:[~2026-09-02 0:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 18:39 [PATCH net] netdevsim: take bus device refcount before registering device Adriano Cordova
2026-09-02 0:06 ` Jakub Kicinski [this message]
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=20260901170626.6136cdf1@kernel.org \
--to=kuba@kernel.org \
--cc=adrianox@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=syzbot+989ff6506f5c6d1ff56b@syzkaller.appspot.com \
/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