Skip to contentSkip to conversation

udp_tunnel: Add checks for nla_nest_start() in __udp_tunnel_nic_dump_write()

PATCH Applied Yuan Can 4 participants 4 messages Nov 29, 2022

Subsystems (2)
lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH v2 1/1 udp_tunnel: Add checks for nla_nest_start() in __udp_tunnel_nic_dump_write()

As the nla_nest_start() may fail with NULL returned, the return value needs to be checked.

Fixes c7d759eb7b12 ("ethtool: add tunnel info interface")

---
Changes in v2:
- return directly without calling nla_nest_cancel if nest_start fails

 net/ipv4/udp_tunnel_nic.c | 2 ++
 1 file changed, 2 insertions(+)
net/ipv4/udp_tunnel_nic.c +2 -0
index bc3a043a5d5c..029219749785 100644
@@ -624,6 +624,8 @@ __udp_tunnel_nic_dump_write(struct net_device *dev, unsigned int table,
 			continue;
 
 		nest = nla_nest_start(skb, ETHTOOL_A_TUNNEL_UDP_TABLE_ENTRY);
+		if (!nest)
+			return -EMSGSIZE;
 
 		if (nla_put_be16(skb, ETHTOOL_A_TUNNEL_UDP_ENTRY_PORT,
 				 utn->entries[table][j].port) ||
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 12 lines · Yuan Can

As the nla_nest_start() may fail with NULL returned, the return value needs to be checked.

Fixes c7d759eb7b12 ("ethtool: add tunnel info interface")

---
Changes in v2:
- return directly without calling nla_nest_cancel if nest_start fails

 net/ipv4/udp_tunnel_nic.c | 2 ++
 1 file changed, 2 insertions(+)
maintainer
#2 lore raw
Quoted 8 lines · On Mon, 28 Nov 2022 20:09:52 -0700 David Ahern wrote:
Quoted 5 lines · Yuan Can

As the nla_nest_start() may fail with NULL returned, the return value needs to be checked.

Fixes c7d759eb7b12 ("ethtool: add tunnel info interface")

Applying to net-next without the Fixes tag, FWIW. The next put will fail and we'll bail all the same, this patch is pretty much a noop. But not the first "fix" like this we go so probably not point fighting it.

Yuan, please try to find some other error checking to run your bots on, I doubt any of the nla_nest_start() uses actually need error checking.

#3 lore raw
In reply to Yuan Can
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Hello:

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

Quoted 10 lines · On Tue, 29 Nov 2022 01:39:34 +0000 you wrote:

As the nla_nest_start() may fail with NULL returned, the return value needs to be checked.

Fixes c7d759eb7b12 ("ethtool: add tunnel info interface")

---
Changes in v2:
- return directly without calling nla_nest_cancel if nest_start fails

[...]

Here is the summary with links:
- [v2] udp_tunnel: Add checks for nla_nest_start() in __udp_tunnel_nic_dump_write()

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

You are awesome, thank you!

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