netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2] net: hold netdev reference during qdisc_create request_module
@ 2025-03-20 16:51 Stanislav Fomichev
  2025-03-24 22:04 ` Jakub Kicinski
  0 siblings, 1 reply; 4+ messages in thread
From: Stanislav Fomichev @ 2025-03-20 16:51 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, kuba, pabeni, linux-kernel, jhs, xiyou.wangcong,
	jiri, horms, sdf

Eric reports that by the time we call netdev_lock_ops after
rtnl_unlock/rtnl_lock, the dev might point to an invalid device.
Add extra dev_hold/dev_put to make sure the device pointer
is still valid after rtnl_unlock.

Fixes: a0527ee2df3f ("net: hold netdev instance lock during qdisc ndo_setup_tc")
Reported-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/netdev/20250305163732.2766420-1-sdf@fomichev.me/T/#me8dfd778ea4c4463acab55644e3f9836bc608771
Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
---
 net/sched/sch_api.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index aef39f6dc6a8..85ddb811780c 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -1280,11 +1280,13 @@ static struct Qdisc *qdisc_create(struct net_device *dev,
 			 * We replay the request because the device may
 			 * go away in the mean time.
 			 */
+			dev_hold(dev);
 			netdev_unlock_ops(dev);
 			rtnl_unlock();
 			request_module(NET_SCH_ALIAS_PREFIX "%s", name);
 			rtnl_lock();
 			netdev_lock_ops(dev);
+			dev_put(dev);
 			ops = qdisc_lookup_ops(kind);
 			if (ops != NULL) {
 				/* We will try again qdisc_lookup_ops,
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-03-25 10:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-20 16:51 [PATCH net-next v2] net: hold netdev reference during qdisc_create request_module Stanislav Fomichev
2025-03-24 22:04 ` Jakub Kicinski
2025-03-24 22:22   ` Stanislav Fomichev
2025-03-25 10:28     ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).