Skip to contentSkip to conversation

netdev: address a handful of nit picks

PATCH Superseded Jakub Kicinski 4 participants 20 messages Jun 9

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

cover netdev: address a handful of nit picks

I got slightly concerned about the state of the netdev-genl implementation after Gemini found the bug fixed by commit c849de7d8757 ("netdev: fix double-free in netdev_nl_bind_rx_doit()"). I fed the file into a couple of models to make sure we're not sitting on more bugs. The models haven't found anything worthy of a Fixes tag but some of the nit picks are borderline worth addressing.

Jakub Kicinski (4):
netdev: check for nla_put_u32() failures
netdev: correct error code in netdev_nl_queue_fill_lease()
netdev: avoid skipping objects on race with device disappearance
netdev: don't use dev->flags for IFF_UP

 net/core/netdev-genl.c | 47 +++++++++++++++++++++++++++++++++---------
 1 file changed, 37 insertions(+), 10 deletions(-)
Signature · 1 line
2.54.0
author maintainer
#1 lore raw

PATCH 1/4 netdev: check for nla_put_u32() failures

Make sure we check if nla_put_u32(id) was successful after creating objects. This is theoretical today, the skbs are large enough to always fit the ID.

---
 net/core/netdev-genl.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
net/core/netdev-genl.c +18 -3
index b4d48f3672a5..a10d353d5eab 100644
@@ -1091,7 +1091,10 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
 			goto err_unbind;
 	}
 
-	nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id);
+	err = nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id);
+	if (err)
+		goto err_unbind;
+
 	genlmsg_end(rsp, hdr);
 
 	err = genlmsg_reply(rsp, info);
@@ -1227,7 +1230,10 @@ int netdev_nl_bind_tx_doit(struct sk_buff *skb, struct genl_info *info)
 		goto err_unlock_bind_dev;
 	}
 
-	nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id);
+	err = nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id);
+	if (err)
+		goto err_unbind;
+
 	genlmsg_end(rsp, hdr);
 
 	if (bind_dev != netdev)
@@ -1237,6 +1243,8 @@ int netdev_nl_bind_tx_doit(struct sk_buff *skb, struct genl_info *info)
 
 	return genlmsg_reply(rsp, info);
 
+err_unbind:
+	net_devmem_unbind_dmabuf(binding);
 err_unlock_bind_dev:
 	if (bind_dev != netdev)
 		netdev_unlock(bind_dev);
@@ -1394,7 +1402,12 @@ int netdev_nl_queue_create_doit(struct sk_buff *skb, struct genl_info *info)
 
 	netdev_rx_queue_lease(rxq, rxq_lease);
 
-	nla_put_u32(rsp, NETDEV_A_QUEUE_ID, queue_id);
+	err = nla_put_u32(rsp, NETDEV_A_QUEUE_ID, queue_id);
+	if (err) {
+		WARN_ON_ONCE(1); /* we can't delete the queue, ID must fit in */
+		goto err_unlease;
+	}
+
 	genlmsg_end(rsp, hdr);
 
 	netdev_unlock(dev_lease);
@@ -1404,6 +1417,8 @@ int netdev_nl_queue_create_doit(struct sk_buff *skb, struct genl_info *info)
 
 	return genlmsg_reply(rsp, info);
 
+err_unlease:
+	netdev_rx_queue_unlease(rxq, rxq_lease);
 err_unlock_dev_lease:
 	netdev_unlock(dev_lease);
 err_put_netns:
Signature · 1 line
2.54.0
author maintainer
#6 lore raw

PATCH 2/4 netdev: correct error code in netdev_nl_queue_fill_lease()

In reply to Jakub Kicinski

netdev_nl_queue_fill_lease() returns ENOMEM on nla_put failures. This is wrong, the error code should be EMSGSIZE. But it doesn't matter, caller of netdev_nl_queue_fill_lease() just checks if the retcode is zero or not, and uses EMSGSIZE.

---
 net/core/netdev-genl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/netdev-genl.c +1 -1
index a10d353d5eab..d35af460e886 100644
@@ -432,7 +432,7 @@ netdev_nl_queue_fill_lease(struct sk_buff *rsp, struct net_device *netdev,
 nla_put_failure_unlock:
 	rcu_read_unlock();
 nla_put_failure:
-	return -ENOMEM;
+	return -EMSGSIZE;
 }
 
 static int
Signature · 1 line
2.54.0
author maintainer
#10 lore raw

PATCH 3/4 netdev: avoid skipping objects on race with device disappearance

In reply to Jakub Kicinski

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.

---
 net/core/netdev-genl.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
net/core/netdev-genl.c +17 -5
index d35af460e886..18046ad0f883 100644
@@ -310,11 +310,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;
 		}
 	}
 
@@ -634,13 +637,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;
 		}
 	}
 
@@ -786,8 +793,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;
 }
 
@@ -902,6 +907,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;
@@ -934,7 +940,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)
Signature · 1 line
2.54.0
author maintainer
#16 lore raw

PATCH 4/4 netdev: don't use dev->flags for IFF_UP

In reply to Jakub Kicinski

dev->flags are not technically ops lock protected. The IFF_UP flag will not change when dev->lock is held, but other flags may change so KCSAN would probably not be impressed. Because of this we added a dedicated dev->up which is safe to read under dev->lock.

qstats want to make sure device is up, use dev->up.

---
 net/core/netdev-genl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/netdev-genl.c +1 -1
index 18046ad0f883..745e2eb6c9af 100644
@@ -773,7 +773,7 @@ netdev_nl_stats_by_queue(struct net_device *netdev, struct sk_buff *rsp,
 	const struct netdev_stat_ops *ops = netdev->stat_ops;
 	int i, err;
 
-	if (!(netdev->flags & IFF_UP))
+	if (!netdev->up)
 		return 0;
 
 	i = ctx->rxq_idx;
Signature · 1 line
2.54.0
Reviewed-by on v1 2/4
#7 lore raw

Re: [PATCH net-next 2/4] netdev: correct error code in netdev_nl_queue_fill_lease()

In reply to Jakub Kicinski
Quoted 27 lines · Jakub Kicinski

netdev_nl_queue_fill_lease() returns ENOMEM on nla_put failures. This is wrong, the error code should be EMSGSIZE. But it doesn't matter, caller of netdev_nl_queue_fill_lease() just checks if the retcode is zero or not, and uses EMSGSIZE.

---
 net/core/netdev-genl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/netdev-genl.c +1 -1
index a10d353d5eab..d35af460e886 100644
@@ -432,7 +432,7 @@ netdev_nl_queue_fill_lease(struct sk_buff *rsp, struct net_device *netdev,
 nla_put_failure_unlock:
 	rcu_read_unlock();
 nla_put_failure:
-	return -ENOMEM;
+	return -EMSGSIZE;
 }
 
 static int
Signature · 1 line
2.54.0
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH net-next 1/4] netdev: check for nla_put_u32() failures

In reply to Jakub Kicinski
Quoted 73 lines · Jakub Kicinski

Make sure we check if nla_put_u32(id) was successful after creating objects. This is theoretical today, the skbs are large enough to always fit the ID.

---
 net/core/netdev-genl.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
net/core/netdev-genl.c +18 -3
index b4d48f3672a5..a10d353d5eab 100644
@@ -1091,7 +1091,10 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
 			goto err_unbind;
 	}
 
-	nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id);
+	err = nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id);
+	if (err)
+		goto err_unbind;
+
 	genlmsg_end(rsp, hdr);
 
 	err = genlmsg_reply(rsp, info);
@@ -1227,7 +1230,10 @@ int netdev_nl_bind_tx_doit(struct sk_buff *skb, struct genl_info *info)
 		goto err_unlock_bind_dev;
 	}
 
-	nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id);
+	err = nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id);
+	if (err)
+		goto err_unbind;
+
 	genlmsg_end(rsp, hdr);
 
 	if (bind_dev != netdev)
@@ -1237,6 +1243,8 @@ int netdev_nl_bind_tx_doit(struct sk_buff *skb, struct genl_info *info)
 
 	return genlmsg_reply(rsp, info);
 
+err_unbind:
+	net_devmem_unbind_dmabuf(binding);
 err_unlock_bind_dev:
 	if (bind_dev != netdev)
 		netdev_unlock(bind_dev);
@@ -1394,7 +1402,12 @@ int netdev_nl_queue_create_doit(struct sk_buff *skb, struct genl_info *info)
 
 	netdev_rx_queue_lease(rxq, rxq_lease);
 
-	nla_put_u32(rsp, NETDEV_A_QUEUE_ID, queue_id);
+	err = nla_put_u32(rsp, NETDEV_A_QUEUE_ID, queue_id);
+	if (err) {
+		WARN_ON_ONCE(1); /* we can't delete the queue, ID must fit in */
+		goto err_unlease;
+	}
+
 	genlmsg_end(rsp, hdr);
 
 	netdev_unlock(dev_lease);
@@ -1404,6 +1417,8 @@ int netdev_nl_queue_create_doit(struct sk_buff *skb, struct genl_info *info)
 
 	return genlmsg_reply(rsp, info);
 
+err_unlease:
+	netdev_rx_queue_unlease(rxq, rxq_lease);
 err_unlock_dev_lease:
 	netdev_unlock(dev_lease);
 err_put_netns:
Signature · 1 line
2.54.0
Acked-by on v1 2/4
#8 lore raw

Re: [PATCH net-next 2/4] netdev: correct error code in netdev_nl_queue_fill_lease()

In reply to Jakub Kicinski
Quoted 6 lines · Jakub Kicinski

netdev_nl_queue_fill_lease() returns ENOMEM on nla_put failures. This is wrong, the error code should be EMSGSIZE. But it doesn't matter, caller of netdev_nl_queue_fill_lease() just checks if the retcode is zero or not, and uses EMSGSIZE.

Acked-by on v1 3/4
#11 lore raw

Re: [PATCH net-next 3/4] netdev: avoid skipping objects on race with device disappearance

In reply to Jakub Kicinski
Quoted 6 lines · Jakub Kicinski

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.

Acked-by on v1 4/4
#17 lore raw

Re: [PATCH net-next 4/4] netdev: don't use dev->flags for IFF_UP

In reply to Jakub Kicinski
Quoted 8 lines · Jakub Kicinski

dev->flags are not technically ops lock protected. The IFF_UP flag will not change when dev->lock is held, but other flags may change so KCSAN would probably not be impressed. Because of this we added a dedicated dev->up which is safe to read under dev->lock.

qstats want to make sure device is up, use dev->up.

#3 lore raw

Re: [PATCH net-next 1/4] netdev: check for nla_put_u32() failures

In reply to Jakub Kicinski
Quoted 14 lines · Jakub Kicinski

Make sure we check if nla_put_u32(id) was successful after creating objects. This is theoretical today, the skbs are large enough to always fit the ID.

---
  net/core/netdev-genl.c | 21 ++++++++++++++++++---
  1 file changed, 18 insertions(+), 3 deletions(-)
net/core/netdev-genl.c +0 -0
index b4d48f3672a5..a10d353d5eab 100644

net/core/netdev-genl.c int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info) · line 1097

Quoted 8 lines
net/core/netdev-genl.c +4 -1
@@ -1091,7 +1091,10 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
  			goto err_unbind;
  	}
 
-	nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id);
+	err = nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id);
+	if (err)
+		goto err_unbind;
+

Not sure about these three tbh... if the skbs are guaranteed to be large enough, would a more straight forward ...

  WARN_ON_ONCE(err);

... suffice? Unwinding at this point feels a bit excessive. Is there any other way we could assert this earlier before we do all the ops that need to be unwound?

Quoted 25 lines
net/core/netdev-genl.c +6 -1
  	genlmsg_end(rsp, hdr);
 
  	err = genlmsg_reply(rsp, info);
@@ -1227,7 +1230,10 @@ int netdev_nl_bind_tx_doit(struct sk_buff *skb, struct genl_info *info)
  		goto err_unlock_bind_dev;
  	}
 
-	nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id);
+	err = nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id);
+	if (err)
+		goto err_unbind;
+
  	genlmsg_end(rsp, hdr);
 
  	if (bind_dev != netdev)
@@ -1237,6 +1243,8 @@ int netdev_nl_bind_tx_doit(struct sk_buff *skb, struct genl_info *info)
 
  	return genlmsg_reply(rsp, info);
 
+err_unbind:
+	net_devmem_unbind_dmabuf(binding);
  err_unlock_bind_dev:
  	if (bind_dev != netdev)
  		netdev_unlock(bind_dev);

net/core/netdev-genl.c int netdev_nl_queue_create_doit(struct sk_buff *skb, struct genl_info *info) · line 1409

Quoted 9 lines
net/core/netdev-genl.c +5 -1
@@ -1394,7 +1402,12 @@ int netdev_nl_queue_create_doit(struct sk_buff *skb, struct genl_info *info)
 
  	netdev_rx_queue_lease(rxq, rxq_lease);
 
-	nla_put_u32(rsp, NETDEV_A_QUEUE_ID, queue_id);
+	err = nla_put_u32(rsp, NETDEV_A_QUEUE_ID, queue_id);
+	if (err) {
+		WARN_ON_ONCE(1); /* we can't delete the queue, ID must fit in */
+		goto err_unlease;
+	}

.. in particular here :/ would be nicer if we could solve it differently

Quoted 13 lines
net/core/netdev-genl.c +3 -0
+
  	genlmsg_end(rsp, hdr);
 
  	netdev_unlock(dev_lease);
@@ -1404,6 +1417,8 @@ int netdev_nl_queue_create_doit(struct sk_buff *skb, struct genl_info *info)
 
  	return genlmsg_reply(rsp, info);
 
+err_unlease:
+	netdev_rx_queue_unlease(rxq, rxq_lease);
  err_unlock_dev_lease:
  	netdev_unlock(dev_lease);
  err_put_netns:
Reviewed-by on v1 4/4
#18 lore raw

Re: [PATCH net-next 4/4] netdev: don't use dev->flags for IFF_UP

In reply to Jakub Kicinski
Quoted 5 lines · Jakub Kicinski

dev->flags are not technically ops lock protected. The IFF_UP flag will not change when dev->lock is held, but other flags may change so KCSAN would probably not be impressed. Because of this we added a dedicated dev->up which is safe to read under dev->lock.

Quoted 7 lines

qstats want to make sure device is up, use dev->up.

---
 net/core/netdev-genl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by on v1 1/4
#5 lore raw

Re: [PATCH net-next 1/4] netdev: check for nla_put_u32() failures

In reply to Jakub Kicinski
Quoted 9 lines · Jakub Kicinski

Make sure we check if nla_put_u32(id) was successful after creating objects. This is theoretical today, the skbs are large enough to always fit the ID.

---
 net/core/netdev-genl.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
Reviewed-by on v1 2/4
#9 lore raw

Re: [PATCH net-next 2/4] netdev: correct error code in netdev_nl_queue_fill_lease()

In reply to Jakub Kicinski
Quoted 10 lines · Jakub Kicinski

netdev_nl_queue_fill_lease() returns ENOMEM on nla_put failures. This is wrong, the error code should be EMSGSIZE. But it doesn't matter, caller of netdev_nl_queue_fill_lease() just checks if the retcode is zero or not, and uses EMSGSIZE.

---
 net/core/netdev-genl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by on v1 3/4
#12 lore raw

Re: [PATCH net-next 3/4] netdev: avoid skipping objects on race with device disappearance

In reply to Jakub Kicinski
Quoted 85 lines · Jakub Kicinski

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.

---
 net/core/netdev-genl.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
net/core/netdev-genl.c +17 -5
index d35af460e886..18046ad0f883 100644
@@ -310,11 +310,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;
 		}
 	}
 
@@ -634,13 +637,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;
 		}
 	}
 
@@ -786,8 +793,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;
 }
 
@@ -902,6 +907,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;
@@ -934,7 +940,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)
Signature · 1 line
2.54.0
Reviewed-by on v1 4/4
#19 lore raw

Re: [PATCH net-next 4/4] netdev: don't use dev->flags for IFF_UP

In reply to Jakub Kicinski
Quoted 29 lines · Jakub Kicinski

dev->flags are not technically ops lock protected. The IFF_UP flag will not change when dev->lock is held, but other flags may change so KCSAN would probably not be impressed. Because of this we added a dedicated dev->up which is safe to read under dev->lock.

qstats want to make sure device is up, use dev->up.

---
 net/core/netdev-genl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/netdev-genl.c +1 -1
index 18046ad0f883..745e2eb6c9af 100644
@@ -773,7 +773,7 @@ netdev_nl_stats_by_queue(struct net_device *netdev, struct sk_buff *rsp,
 	const struct netdev_stat_ops *ops = netdev->stat_ops;
 	int i, err;
 
-	if (!(netdev->flags & IFF_UP))
+	if (!netdev->up)
 		return 0;
 
 	i = ctx->rxq_idx;
Signature · 1 line
2.54.0
#13 lore raw

Re: [PATCH net-next 3/4] netdev: avoid skipping objects on race with device disappearance

In reply to Bobby Eshleman
Quoted 72 lines · Bobby Eshleman
Quoted 71 lines · Jakub Kicinski

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.

---
 net/core/netdev-genl.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
net/core/netdev-genl.c +11 -5
index d35af460e886..18046ad0f883 100644
@@ -310,11 +310,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;
 		}
 	}
 
@@ -634,13 +637,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;
 		}
 	}
 
@@ -786,8 +793,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;
 }
 
@@ -902,6 +907,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;
@@ -934,7 +940,13 @@ int netdev_nl_qstats_get_dumpit(struct sk_buff *skb,
 		return err;
 	}
 
Quoted 16 lines
Quoted 14 lines
net/core/netdev-genl.c +6 -0
+	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)
Signature · 1 line
2.54.0

I just noticed we handle this differently in rtnetlink with cb->seq/dev_base_seq/nl_dump_check_consistent(), but it seems like netdev-genl.c intentionally does not use NLM_F_DUMP_INTR?

Best,
Bobby

author maintainer
#14 lore raw

Re: [PATCH net-next 3/4] netdev: avoid skipping objects on race with device disappearance

Quoted 3 lines · On Tue, 9 Jun 2026 13:15:05 -0700 Bobby Eshleman wrote:

I just noticed we handle this differently in rtnetlink with cb->seq/dev_base_seq/nl_dump_check_consistent(), but it seems like netdev-genl.c intentionally does not use NLM_F_DUMP_INTR?

Intentionally is a strong word, but yes, it's "known".

My mental model is that DUMP_INTR is required when we are dumping unordered lists. In those cases we just count "how many objects were already dumped", so if we dumped 4 objects then object #1 is removed the dump will resume from object which was previously #6 thinking that it's #5 and #5 will never be dumped.

In netdev objects have ordered IDs, we don't count.

But in theory we probably maybe should also indicate consistency. Nobody seems to care in practice.

#15 lore raw

Re: [PATCH net-next 3/4] netdev: avoid skipping objects on race with device disappearance

Quoted 13 lines · Jakub Kicinski
Quoted 3 lines · On Tue, 9 Jun 2026 13:15:05 -0700 Bobby Eshleman wrote:

I just noticed we handle this differently in rtnetlink with cb->seq/dev_base_seq/nl_dump_check_consistent(), but it seems like netdev-genl.c intentionally does not use NLM_F_DUMP_INTR?

Intentionally is a strong word, but yes, it's "known".

My mental model is that DUMP_INTR is required when we are dumping unordered lists. In those cases we just count "how many objects were already dumped", so if we dumped 4 objects then object #1 is removed the dump will resume from object which was previously #6 thinking that it's #5 and #5 will never be dumped.

Quoted 4 lines

In netdev objects have ordered IDs, we don't count.

But in theory we probably maybe should also indicate consistency. Nobody seems to care in practice.

gotcha, thanks for the clarification.

-Bobby

author maintainer
#4 lore raw

Re: [PATCH net-next 1/4] netdev: check for nla_put_u32() failures

In reply to Daniel Borkmann
Quoted 9 lines · On Tue, 9 Jun 2026 21:52:25 +0200 Daniel Borkmann wrote:

net/core/netdev-genl.c int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info) · line 1097

Quoted 5 lines
net/core/netdev-genl.c +4 -1
-	nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id);
+	err = nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id);
+	if (err)
+		goto err_unbind;
+  

Not sure about these three tbh... if the skbs are guaranteed to be large enough, would a more straight forward ...

Quoted 3 lines
   WARN_ON_ONCE(err);

... suffice?

Sure, I guess it's subjective whether it's better to add a WARN and have to explain why it can never happen or just call the undo function since it's already available :)

Quoted 3 lines

Unwinding at this point feels a bit excessive. Is there any other way we could assert this earlier before we do all the ops that need to be unwound?

It's dead code. We keep getting patches for "nla_* return value not checked" tho, so if decided to squash these while at it..

I'll respin with WARN