Commit b51fb771 authored by Michal Kubecek's avatar Michal Kubecek Committed by David S. Miller

ethtool: fix reference leak in ethnl_set_privflags()

Andrew noticed that some handlers for *_SET commands leak a netdev
reference if required ethtool_ops callbacks do not exist. One of them is
ethnl_set_privflags(), a simple reproducer would be e.g.

  ip link add veth1 type veth peer name veth2
  ethtool --set-priv-flags veth1 foo on
  ip link del veth1

Make sure dev_put() is called when ethtool_ops check fails.

Fixes: f265d799 ("ethtool: set device private flags with PRIVFLAGS_SET request")
Reported-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarMichal Kubecek <mkubecek@suse.cz>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 96376cad
...@@ -175,9 +175,10 @@ int ethnl_set_privflags(struct sk_buff *skb, struct genl_info *info) ...@@ -175,9 +175,10 @@ int ethnl_set_privflags(struct sk_buff *skb, struct genl_info *info)
return ret; return ret;
dev = req_info.dev; dev = req_info.dev;
ops = dev->ethtool_ops; ops = dev->ethtool_ops;
ret = -EOPNOTSUPP;
if (!ops->get_priv_flags || !ops->set_priv_flags || if (!ops->get_priv_flags || !ops->set_priv_flags ||
!ops->get_sset_count || !ops->get_strings) !ops->get_sset_count || !ops->get_strings)
return -EOPNOTSUPP; goto out_dev;
rtnl_lock(); rtnl_lock();
ret = ethnl_ops_begin(dev); ret = ethnl_ops_begin(dev);
...@@ -204,6 +205,7 @@ int ethnl_set_privflags(struct sk_buff *skb, struct genl_info *info) ...@@ -204,6 +205,7 @@ int ethnl_set_privflags(struct sk_buff *skb, struct genl_info *info)
ethnl_ops_complete(dev); ethnl_ops_complete(dev);
out_rtnl: out_rtnl:
rtnl_unlock(); rtnl_unlock();
out_dev:
dev_put(dev); dev_put(dev);
return ret; return ret;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment