ethtool: fix reference leak in some *_SET handlers
Subsystems (3)
PATCH v2 1/1 ethtool: fix reference leak in some *_SET handlers
Andrew noticed that some handlers for *_SET commands leak a netdev reference if required ethtool_ops callbacks do not exist. A simple reproducer would be e.g.
ip link add veth1 type veth peer name veth2
ethtool -s veth1 wol g
ip link del veth1
Make sure dev_put() is called when ethtool_ops check fails.
v2: add Fixes tags
--- net/ethtool/debug.c | 4 +++- net/ethtool/linkinfo.c | 4 +++- net/ethtool/linkmodes.c | 4 +++- net/ethtool/wol.c | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-)
net/ethtool/debug.c +3 -1
@@ -107,8 +107,9 @@ int ethnl_set_debug(struct sk_buff *skb, struct genl_info *info)if (ret <0 )return ret; dev = req_info.dev; + ret = -EOPNOTSUPP ;if (!dev->ethtool_ops->get_msglevel || !dev->ethtool_ops->set_msglevel) -return -EOPNOTSUPP ; + goto out_dev;rtnl_lock (); ret =ethnl_ops_begin (dev);
@@ -129,6 +130,7 @@ int ethnl_set_debug(struct sk_buff *skb, struct genl_info *info)ethnl_ops_complete (dev); out_rtnl:rtnl_unlock (); +out_dev:dev_put (dev);return ret; }
net/ethtool/linkinfo.c +3 -1
@@ -126,9 +126,10 @@ int ethnl_set_linkinfo(struct sk_buff *skb, struct genl_info *info)if (ret <0 )return ret; dev = req_info.dev; + ret = -EOPNOTSUPP ;if (!dev->ethtool_ops->get_link_ksettings || !dev->ethtool_ops->set_link_ksettings) -return -EOPNOTSUPP ; + goto out_dev;rtnl_lock (); ret =ethnl_ops_begin (dev);
@@ -162,6 +163,7 @@ int ethnl_set_linkinfo(struct sk_buff *skb, struct genl_info *info)ethnl_ops_complete (dev); out_rtnl:rtnl_unlock (); +out_dev:dev_put (dev);return ret; }
net/ethtool/linkmodes.c +3 -1
@@ -338,9 +338,10 @@ int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info)if (ret <0 )return ret; dev = req_info.dev; + ret = -EOPNOTSUPP ;if (!dev->ethtool_ops->get_link_ksettings || !dev->ethtool_ops->set_link_ksettings) -return -EOPNOTSUPP ; + goto out_dev;rtnl_lock (); ret =ethnl_ops_begin (dev);
@@ -370,6 +371,7 @@ int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info)ethnl_ops_complete (dev); out_rtnl:rtnl_unlock (); +out_dev:dev_put (dev);return ret; }
net/ethtool/wol.c +3 -1
@@ -128,8 +128,9 @@ int ethnl_set_wol(struct sk_buff *skb, struct genl_info *info)if (ret <0 )return ret; dev = req_info.dev; + ret = -EOPNOTSUPP ;if (!dev->ethtool_ops->get_wol || !dev->ethtool_ops->set_wol) -return -EOPNOTSUPP ; + goto out_dev;rtnl_lock (); ret =ethnl_ops_begin (dev);
@@ -172,6 +173,7 @@ int ethnl_set_wol(struct sk_buff *skb, struct genl_info *info)ethnl_ops_complete (dev); out_rtnl:rtnl_unlock (); +out_dev:dev_put (dev);return ret; }
Signature · 1 line
2.25.1
From: Michal Kubecek <[email protected]>
Date: Sun, 22 Mar 2020 22:24:21 +0100 (CET)
Quoted 12 lines
Andrew noticed that some handlers for
*_SETcommands leak a netdev reference if requiredethtool_opscallbacks do not exist. A simple reproducer would be e.g.ip link add veth1 type veth peer name veth2
ethtool -s veth1 wol g
ip link del veth1Make sure
dev_put()is called whenethtool_opscheck fails.v2: add Fixes tags
Quoted 9 lines
Fixes a53f3d41e4d3 ("ethtool: set link settings with LINKINFO_SET request")Fixes bfbcfe2032e7 ("ethtool: set link modes related data with LINKMODES_SET request")Fixes e54d04e3afea ("ethtool: set message mask with DEBUG_SET request")Fixes 8d425b19b305 ("ethtool: set wake-on-lan settings with WOL_SET request")Reported-by Andrew Lunn <[email protected]>Signed-off-by Michal Kubecek <[email protected]>Reviewed-by Andrew Lunn <[email protected]>Reviewed-by Florian Fainelli <[email protected]>Reviewed-by Jakub Kicinski <[email protected]>
Applied, thanks Michal.