Skip to contentSkip to conversation

netdev: check for nla_put_u32() failures

PATCH Applied Jakub Kicinski 5 participants 5 messages Aug 9 – Aug 10

Subsystems (2)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 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.

---
v2:
- don't handle, just WARN
v1: https://lore.kernel.org/[email protected]

---
 net/core/netdev-genl.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
net/core/netdev-genl.c +9 -3
index c0a86f3ae33b..fa9edfdb32c2 100644
@@ -1119,7 +1119,9 @@ 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);
+	/* rsp was allocated large enough */
+	WARN_ON_ONCE(nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id));
+
 	genlmsg_end(rsp, hdr);
 
 	err = genlmsg_reply(rsp, info);
@@ -1253,7 +1255,9 @@ 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);
+	/* rsp was allocated large enough */
+	WARN_ON_ONCE(nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id));
+
 	genlmsg_end(rsp, hdr);
 
 	if (bind_dev != netdev)
@@ -1420,7 +1424,9 @@ 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);
+	/* rsp was allocated large enough */
+	WARN_ON_ONCE(nla_put_u32(rsp, NETDEV_A_QUEUE_ID, queue_id));
+
 	genlmsg_end(rsp, hdr);
 
 	netdev_unlock(dev_lease);
Signature · 1 line
2.55.0
Reviewed-by on v1 1/1
#2 lore raw
In reply to Jakub Kicinski
Quoted 47 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.

---
v2:
- don't handle, just WARN
v1: https://lore.kernel.org/[email protected]

---
  net/core/netdev-genl.c | 12 +++++++++---
  1 file changed, 9 insertions(+), 3 deletions(-)
net/core/netdev-genl.c +6 -2
index c0a86f3ae33b..fa9edfdb32c2 100644
@@ -1119,7 +1119,9 @@ 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);
+	/* rsp was allocated large enough */
+	WARN_ON_ONCE(nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id));
+
  	genlmsg_end(rsp, hdr);
 
  	err = genlmsg_reply(rsp, info);
@@ -1253,7 +1255,9 @@ 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);
+	/* rsp was allocated large enough */
+	WARN_ON_ONCE(nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id));
+
  	genlmsg_end(rsp, hdr);
 
  	if (bind_dev != netdev)

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

Quoted 10 lines
net/core/netdev-genl.c +3 -1
@@ -1420,7 +1424,9 @@ 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);
+	/* rsp was allocated large enough */
+	WARN_ON_ONCE(nla_put_u32(rsp, NETDEV_A_QUEUE_ID, queue_id));
+
  	genlmsg_end(rsp, hdr);
 
  	netdev_unlock(dev_lease);
Reviewed-by on v1 1/1
#3 lore raw
In reply to Jakub Kicinski
Quoted 16 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.

---
v2:
- don't handle, just WARN
v1: https://lore.kernel.org/[email protected]

Quoted 4 lines
---
 net/core/netdev-genl.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
#4 lore raw
In reply to Jakub Kicinski
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 11 lines · On Sat, 8 Aug 2026 17:06:09 -0700 you wrote:

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.

---
v2:
- don't handle, just WARN
v1: https://lore.kernel.org/[email protected]

[...]

Here is the summary with links:
- [net-next] netdev: check for nla_put_u32() failures

    https://git.kernel.org/netdev/net-next/c/ae2998ab62e4

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html