From: Thanh Nguyen <thanhnguyentuan2007@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>
Cc: Jiri Pirko <jiri@nvidia.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
syzbot+a104228f8a378b00e6ad@syzkaller.appspotmail.com,
Thanh Nguyen <thanhnguyentuan2007@gmail.com>
Subject: [PATCH net] netdevsim: allow reload_down when current netns is exiting
Date: Fri, 4 Dec 2026 09:16:19 -0500 [thread overview]
Message-ID: <20261204141619.1630-1-thanhnguyentuan2007@gmail.com> (raw)
When a network namespace containing a netdevsim instance is destroyed,
devlink_pernet_pre_exit() reloads the devlink instance back into
init_net. If debugfs dont_allow_reload is set, nsim_dev_reload_down()
returns -EOPNOTSUPP without tearing down netdevsim's per-netns
notifiers (hwstats netdevice_nb, fib_nb, nexthop_nb), yet
devlink_pernet_pre_exit() still moves devlink_net(devlink) to
init_net.
Subsequently, when nsim_dev_hwstats_exit() runs during device removal
or reload, it calls unregister_netdevice_notifier_net() against
init_net instead of the exiting namespace, silently failing with
-ENOENT and destroying hwstats->hwsdev_list_lock while netdevice_nb
remains linked on the exiting namespace's netdev_chain. Remaining
teardown in cleanup_net() then invokes nsim_dev_netdevice_event() on
the destroyed mutex / freed nsim_dev, triggering
DEBUG_LOCKS_WARN_ON(lock->magic != lock) and a use-after-free.
Do not let dont_allow_reload reject reload_down() when the current
network namespace is already being destroyed (!check_net()), so
nsim_dev_reload_destroy() cleanly unregisters all per-netns notifiers
before devlink transitions the instance to init_net.
Reported-by: syzbot+a104228f8a378b00e6ad@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=a104228f8a378b00e6ad
Fixes: 6b3e73774815 ("devlink: fix reload error on netns teardown")
Signed-off-by: Thanh Nguyen <thanhnguyentuan2007@gmail.com>
---
drivers/net/netdevsim/dev.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
index c6b17b387..f016a97e1 100644
--- a/drivers/net/netdevsim/dev.c
+++ b/drivers/net/netdevsim/dev.c
@@ -951,9 +951,10 @@ static int nsim_dev_reload_down(struct devlink *devlink, bool netns_change,
{
struct nsim_dev *nsim_dev = devlink_priv(devlink);
- if (nsim_dev->dont_allow_reload) {
+ if (nsim_dev->dont_allow_reload && check_net(devlink_net(devlink))) {
/* For testing purposes, user set debugfs dont_allow_reload
- * value to true. So forbid it.
+ * value to true. So forbid it, unless the current network
+ * namespace is being destroyed.
*/
NL_SET_ERR_MSG_MOD(extack, "User forbid the reload for testing purposes");
return -EOPNOTSUPP;
--
2.56.1
reply other threads:[~2026-12-04 14:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261204141619.1630-1-thanhnguyentuan2007@gmail.com \
--to=thanhnguyentuan2007@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jiri@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=syzbot+a104228f8a378b00e6ad@syzkaller.appspotmail.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