Skip to contentSkip to conversation

ethtool: always write dev in ethnl_parse_header_dev_get

PATCH Applied Jakub Kicinski 3 participants 3 messages Dec 14, 2021 – Dec 15, 2021

Subsystems (3)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 ethtool: always write dev in ethnl_parse_header_dev_get

Commit 0976b888a150 ("ethtool: fix null-ptr-deref on ref tracker") made the write to req_info.dev conditional, but as Eric points out in a different follow up the structure is often allocated on the stack and not kzalloc()'d so seems safer to always write the dev, in case it's garbage on input.

---
 net/ethtool/netlink.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
net/ethtool/netlink.c +2 -3
index 767fb3f17267..f09c62302a9a 100644
@@ -141,10 +141,9 @@ int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info,
 		return -EINVAL;
 	}
 
-	if (dev) {
-		req_info->dev = dev;
+	req_info->dev = dev;
+	if (dev)
 		netdev_tracker_alloc(dev, &req_info->dev_tracker, GFP_KERNEL);
-	}
 	req_info->flags = flags;
 	return 0;
 }
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jakub Kicinski

Commit 0976b888a150 ("ethtool: fix null-ptr-deref on ref tracker") made the write to req_info.dev conditional, but as Eric points out in a different follow up the structure is often allocated on the stack and not kzalloc()'d so seems safer to always write the dev, in case it's garbage on input.

Yep, this was basically how I wanted to fix this.

Quoted 21 lines
---
  net/ethtool/netlink.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
net/ethtool/netlink.c +2 -3
index 767fb3f17267..f09c62302a9a 100644
@@ -141,10 +141,9 @@ int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info,
  		return -EINVAL;
  	}
 
-	if (dev) {
-		req_info->dev = dev;
+	req_info->dev = dev;
+	if (dev)
  		netdev_tracker_alloc(dev, &req_info->dev_tracker, GFP_KERNEL);
-	}
  	req_info->flags = flags;
  	return 0;
  }
#2 lore raw
In reply to Jakub Kicinski
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

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

Quoted 9 lines · On Tue, 14 Dec 2021 07:47:25 -0800 you wrote:

Commit 0976b888a150 ("ethtool: fix null-ptr-deref on ref tracker") made the write to req_info.dev conditional, but as Eric points out in a different follow up the structure is often allocated on the stack and not kzalloc()'d so seems safer to always write the dev, in case it's garbage on input.

[...]

Here is the summary with links:
- [net-next] ethtool: always write dev in ethnl_parse_header_dev_get

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

You are awesome, thank you!

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