From 0976b888a150476ba955ce4765858824c633cfd2 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Mon, 13 Dec 2021 17:39:02 -0800 Subject: [PATCH] ethtool: fix null-ptr-deref on ref tracker dev can be a NULL here, not all requests set require_dev. Fixes: e4b8954074f6 ("netlink: add net device refcount tracker to struct ethnl_req_info") Signed-off-by: Jakub Kicinski Reviewed-by: Eric Dumazet Signed-off-by: David S. Miller --- net/ethtool/netlink.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 23f32a995099..767fb3f17267 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -141,8 +141,10 @@ int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info, return -EINVAL; } - req_info->dev = dev; - netdev_tracker_alloc(dev, &req_info->dev_tracker, GFP_KERNEL); + if (dev) { + req_info->dev = dev; + netdev_tracker_alloc(dev, &req_info->dev_tracker, GFP_KERNEL); + } req_info->flags = flags; return 0; }