From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
andrew+netdev@lunn.ch, horms@kernel.org,
Jakub Kicinski <kuba@kernel.org>,
Bobby Eshleman <bobbyeshleman@meta.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Nikolay Aleksandrov <razor@blackwall.org>
Subject: [PATCH net-next v3] netdev: avoid skipping objects on race with device disappearance
Date: Thu, 3 Sep 2026 15:11:54 -0700 [thread overview]
Message-ID: <20260903221154.3359889-1-kuba@kernel.org> (raw)
If the currently dumped device disappears while we were mid-dump
we will get the next device without resetting the sub-object ID.
This is quite unlikely, it was reported by an AI tool not a real
user. Let's fix it for better dump consistency.
We only intend to cover the case where device A disappears
and we skip over sub-objects of device B which was stable (B existed
before and after the dump). We don't intend to provide stable
results for any device that gets created or deleted during
the dump.
Reviewed-by: Bobby Eshleman <bobbyeshleman@meta.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v3: cover page pool dump as well
v2: https://lore.kernel.org/20260831164159.1124679-3-kuba@kernel.org
v1: https://lore.kernel.org/20260609190804.1137085-1-kuba@kernel.org
---
net/core/netdev-genl.c | 22 +++++++++++++++++-----
net/core/page_pool_user.c | 8 ++++++--
2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
index b8ba91cc93da..fa9edfdb32c2 100644
--- a/net/core/netdev-genl.c
+++ b/net/core/netdev-genl.c
@@ -312,11 +312,14 @@ int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
err = -ENODEV;
}
} else {
+ unsigned long start_ifindex = ctx->ifindex;
+
for_each_netdev_lock_scoped(net, netdev, ctx->ifindex) {
+ if (ctx->ifindex != start_ifindex)
+ ctx->napi_id = 0;
err = netdev_nl_napi_dump_one(netdev, skb, info, ctx);
if (err < 0)
break;
- ctx->napi_id = 0;
}
}
@@ -636,13 +639,17 @@ int netdev_nl_queue_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
err = -ENODEV;
}
} else {
+ unsigned long start_ifindex = ctx->ifindex;
+
for_each_netdev_lock_ops_compat_scoped(net, netdev,
ctx->ifindex) {
+ if (ctx->ifindex != start_ifindex) {
+ ctx->rxq_idx = 0;
+ ctx->txq_idx = 0;
+ }
err = netdev_nl_queue_dump_one(netdev, skb, info, ctx);
if (err < 0)
break;
- ctx->rxq_idx = 0;
- ctx->txq_idx = 0;
}
}
@@ -788,8 +795,6 @@ netdev_nl_stats_by_queue(struct net_device *netdev, struct sk_buff *rsp,
ctx->txq_idx = ++i;
}
- ctx->rxq_idx = 0;
- ctx->txq_idx = 0;
return 0;
}
@@ -904,6 +909,7 @@ int netdev_nl_qstats_get_dumpit(struct sk_buff *skb,
struct netdev_nl_dump_ctx *ctx = netdev_dump_ctx(cb);
const struct genl_info *info = genl_info_dump(cb);
struct net *net = sock_net(skb->sk);
+ unsigned long start_ifindex;
struct net_device *netdev;
unsigned int ifindex;
unsigned int scope;
@@ -936,7 +942,13 @@ int netdev_nl_qstats_get_dumpit(struct sk_buff *skb,
return err;
}
+ start_ifindex = ctx->ifindex;
+
for_each_netdev_lock_ops_compat_scoped(net, netdev, ctx->ifindex) {
+ if (ctx->ifindex != start_ifindex) {
+ ctx->rxq_idx = 0;
+ ctx->txq_idx = 0;
+ }
err = netdev_nl_qstats_get_dump_one(netdev, scope, skb,
info, ctx);
if (err < 0)
diff --git a/net/core/page_pool_user.c b/net/core/page_pool_user.c
index ef4261c0e8ea..f30f3779624c 100644
--- a/net/core/page_pool_user.c
+++ b/net/core/page_pool_user.c
@@ -84,6 +84,7 @@ netdev_nl_page_pool_get_dump(struct sk_buff *skb, struct netlink_callback *cb,
struct page_pool_dump_cb *state = (void *)cb->ctx;
const struct genl_info *info = genl_info_dump(cb);
struct net *net = sock_net(skb->sk);
+ unsigned long start_ifindex;
struct net_device *netdev;
struct page_pool *pool;
int err = 0;
@@ -91,6 +92,8 @@ netdev_nl_page_pool_get_dump(struct sk_buff *skb, struct netlink_callback *cb,
if (ifindex_attr)
state->ifindex = nla_get_u32(ifindex_attr);
+ start_ifindex = state->ifindex;
+
rtnl_lock();
mutex_lock(&page_pools_lock);
for_each_netdev_dump(net, netdev, state->ifindex) {
@@ -99,6 +102,9 @@ netdev_nl_page_pool_get_dump(struct sk_buff *skb, struct netlink_callback *cb,
netdev->ifindex != nla_get_u32(ifindex_attr))
break;
+ if (state->ifindex != start_ifindex)
+ state->pp_id = 0;
+
hlist_for_each_entry(pool, &netdev->page_pools, user.list) {
if (state->pp_id && state->pp_id < pool->user.id)
continue;
@@ -108,8 +114,6 @@ netdev_nl_page_pool_get_dump(struct sk_buff *skb, struct netlink_callback *cb,
if (err)
goto out;
}
-
- state->pp_id = 0;
}
out:
mutex_unlock(&page_pools_lock);
--
2.55.0
next reply other threads:[~2026-09-03 22:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 22:11 Jakub Kicinski [this message]
2026-09-03 23:08 ` [PATCH net-next v3] netdev: avoid skipping objects on race with device disappearance Eric Dumazet
2026-09-03 23:32 ` Jakub Kicinski
2026-09-04 23:20 ` patchwork-bot+netdevbpf
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=20260903221154.3359889-1-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=bobbyeshleman@meta.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.