ethtool: always write dev in ethnl_parse_header_dev_get
authorJakub Kicinski <kuba@kernel.org>
Tue, 14 Dec 2021 15:47:25 +0000 (07:47 -0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 15 Dec 2021 15:09:24 +0000 (15:09 +0000)
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.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ethtool/netlink.c

index 767fb3f..f09c623 100644 (file)
@@ -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;
 }