Skip to contentSkip to conversation

ethtool: fix reference leak in some *_SET handlers

PATCH Superseded Michal Kubecek 4 participants 7 messages Mar 22, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

---
 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
index aaef4843e6ba..92599ad7b3c2 100644
@@ -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
index 5d16cb4e8693..6e9e0b590bb5 100644
@@ -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
index 96f20be64553..18cc37be2d9c 100644
@@ -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
index e1b8a65b64c4..55e1ecaaf739 100644
@@ -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
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Michal Kubecek

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.

Quoted 8 lines

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.

Andrew

Reviewed-by on v1 1/1
#2 lore raw
In reply to Michal Kubecek
Quoted 4 lines · Michal Kubecek

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.

Quoted 8 lines

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.

Would not you want a Fixes: tag for this change?

Signature · 1 line
Florian
maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Michal Kubecek
Quoted 9 lines · On Sun, 22 Mar 2020 21:15:51 +0100 (CET) Michal Kubecek wrote:

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.

Fixes e54d04e3afea ("ethtool: set message mask with DEBUG_SET request")
Fixes a53f3d41e4d3 ("ethtool: set link settings with LINKINFO_SET request")
Fixes bfbcfe2032e7 ("ethtool: set link modes related data with LINKMODES_SET request")
Fixes 8d425b19b305 ("ethtool: set wake-on-lan settings with WOL_SET request")
Quoted 2 lines
#4 lore raw
Quoted 9 lines · Jakub Kicinski
Quoted 8 lines · On Sun, 22 Mar 2020 21:15:51 +0100 (CET) Michal Kubecek wrote:

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

Quoted 6 lines
Quoted 1 line

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

Fixes e54d04e3afea ("ethtool: set message mask with DEBUG_SET request")
Fixes a53f3d41e4d3 ("ethtool: set link settings with LINKINFO_SET request")
Fixes bfbcfe2032e7 ("ethtool: set link modes related data with LINKMODES_SET request")
Fixes 8d425b19b305 ("ethtool: set wake-on-lan settings with WOL_SET request")

Yes, thank you, I forgot about Fixes tags.

Should I resubmit or will patchworks pick the tags from your reply?

Michal

Quoted 4 lines
Quoted 2 lines
maintainer
#5 lore raw
Quoted 12 lines · On Sun, 22 Mar 2020 21:51:09 +0100 Michal Kubecek wrote:
Quoted 11 lines · Jakub Kicinski
Quoted 9 lines · On Sun, 22 Mar 2020 21:15:51 +0100 (CET) Michal Kubecek wrote:

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.

Quoted 8 lines
Quoted 4 lines
Fixes e54d04e3afea ("ethtool: set message mask with DEBUG_SET request")
Fixes a53f3d41e4d3 ("ethtool: set link settings with LINKINFO_SET request")
Fixes bfbcfe2032e7 ("ethtool: set link modes related data with LINKMODES_SET request")
Fixes 8d425b19b305 ("ethtool: set wake-on-lan settings with WOL_SET request")

Yes, thank you, I forgot about Fixes tags.

Should I resubmit or will patchworks pick the tags from your reply?

Patchwork sees them, I think, but I don't think it adds them to the patch as downloaded by git-pw. Probably easiest to repost.

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
#6 lore raw
Quoted 18 lines · Jakub Kicinski
Quoted 17 lines · On Sun, 22 Mar 2020 21:51:09 +0100 Michal Kubecek wrote:
Quoted 15 lines · Jakub Kicinski
Quoted 9 lines · On Sun, 22 Mar 2020 21:15:51 +0100 (CET) Michal Kubecek wrote:

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.

Fixes e54d04e3afea ("ethtool: set message mask with DEBUG_SET request")
Fixes a53f3d41e4d3 ("ethtool: set link settings with LINKINFO_SET request")
Fixes bfbcfe2032e7 ("ethtool: set link modes related data with LINKMODES_SET request")
Fixes 8d425b19b305 ("ethtool: set wake-on-lan settings with WOL_SET request")
Quoted 6 lines
Quoted 3 lines

Yes, thank you, I forgot about Fixes tags.

Should I resubmit or will patchworks pick the tags from your reply?

Patchwork sees them, I think, but I don't think it adds them to the patch as downloaded by git-pw. Probably easiest to repost.

Sent v2 with Fixes and Reviewed-by tags.

Michal

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines