diff mbox series

[net] ethtool: fix error paths in ethnl_set_channels()

Message ID 20201215090810.801777-1-ivecera@redhat.com (mailing list archive)
State Accepted
Delegated to: Netdev Maintainers
Headers show
Series [net] ethtool: fix error paths in ethnl_set_channels() | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net
netdev/subject_prefix success Link
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 20 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 1
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Ivan Vecera Dec. 15, 2020, 9:08 a.m. UTC
Fix two error paths in ethnl_set_channels() to avoid lock-up caused
but unreleased RTNL.

Fixes: e19c591eafad ("ethtool: set device channel counts with CHANNELS_SET request")
Cc: Michal Kubecek <mkubecek@suse.cz>
Reported-by: LiLiang <liali@redhat.com>
Signed-off-by: Ivan Vecera <ivecera@redhat.com>
---
 net/ethtool/channels.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Michal Kubecek Dec. 15, 2020, 10:09 a.m. UTC | #1
On Tue, Dec 15, 2020 at 10:08:10AM +0100, Ivan Vecera wrote:
> Fix two error paths in ethnl_set_channels() to avoid lock-up caused
> but unreleased RTNL.
> 
> Fixes: e19c591eafad ("ethtool: set device channel counts with CHANNELS_SET request")
> Cc: Michal Kubecek <mkubecek@suse.cz>
> Reported-by: LiLiang <liali@redhat.com>
> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
> ---
>  net/ethtool/channels.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/net/ethtool/channels.c b/net/ethtool/channels.c
> index 5635604cb9ba..25a9e566ef5c 100644
> --- a/net/ethtool/channels.c
> +++ b/net/ethtool/channels.c
> @@ -194,8 +194,9 @@ int ethnl_set_channels(struct sk_buff *skb, struct genl_info *info)
>  	if (netif_is_rxfh_configured(dev) &&
>  	    !ethtool_get_max_rxfh_channel(dev, &max_rx_in_use) &&
>  	    (channels.combined_count + channels.rx_count) <= max_rx_in_use) {
> +		ret = -EINVAL;
>  		GENL_SET_ERR_MSG(info, "requested channel counts are too low for existing indirection table settings");
> -		return -EINVAL;
> +		goto out_ops;
>  	}
>  
>  	/* Disabling channels, query zero-copy AF_XDP sockets */
> @@ -203,8 +204,9 @@ int ethnl_set_channels(struct sk_buff *skb, struct genl_info *info)
>  		       min(channels.rx_count, channels.tx_count);
>  	for (i = from_channel; i < old_total; i++)
>  		if (xsk_get_pool_from_qid(dev, i)) {
> +			ret = -EINVAL;
>  			GENL_SET_ERR_MSG(info, "requested channel counts are too low for existing zerocopy AF_XDP sockets");
> -			return -EINVAL;
> +			goto out_ops;
>  		}
>  
>  	ret = dev->ethtool_ops->set_channels(dev, &channels);

Oh, the joys of mindless copy and paste... :-(

Reviewed-by: Michal Kubecek <mkubecek@suse.cz>
Jakub Kicinski Dec. 16, 2020, 9:31 p.m. UTC | #2
On Tue, 15 Dec 2020 11:09:21 +0100 Michal Kubecek wrote:
> On Tue, Dec 15, 2020 at 10:08:10AM +0100, Ivan Vecera wrote:
> > Fix two error paths in ethnl_set_channels() to avoid lock-up caused
> > but unreleased RTNL.
> > 
> > Fixes: e19c591eafad ("ethtool: set device channel counts with CHANNELS_SET request")
> > Cc: Michal Kubecek <mkubecek@suse.cz>
> > Reported-by: LiLiang <liali@redhat.com>
> > Signed-off-by: Ivan Vecera <ivecera@redhat.com>
>
> Oh, the joys of mindless copy and paste... :-(

I wish sparse was able to catch rtnl_lock leaks. I tried to annotate
it a couple of weeks back but couldn't get it to work well even within
rtnetlink.c

> Reviewed-by: Michal Kubecek <mkubecek@suse.cz>

Applied, thanks!
diff mbox series

Patch

diff --git a/net/ethtool/channels.c b/net/ethtool/channels.c
index 5635604cb9ba..25a9e566ef5c 100644
--- a/net/ethtool/channels.c
+++ b/net/ethtool/channels.c
@@ -194,8 +194,9 @@  int ethnl_set_channels(struct sk_buff *skb, struct genl_info *info)
 	if (netif_is_rxfh_configured(dev) &&
 	    !ethtool_get_max_rxfh_channel(dev, &max_rx_in_use) &&
 	    (channels.combined_count + channels.rx_count) <= max_rx_in_use) {
+		ret = -EINVAL;
 		GENL_SET_ERR_MSG(info, "requested channel counts are too low for existing indirection table settings");
-		return -EINVAL;
+		goto out_ops;
 	}
 
 	/* Disabling channels, query zero-copy AF_XDP sockets */
@@ -203,8 +204,9 @@  int ethnl_set_channels(struct sk_buff *skb, struct genl_info *info)
 		       min(channels.rx_count, channels.tx_count);
 	for (i = from_channel; i < old_total; i++)
 		if (xsk_get_pool_from_qid(dev, i)) {
+			ret = -EINVAL;
 			GENL_SET_ERR_MSG(info, "requested channel counts are too low for existing zerocopy AF_XDP sockets");
-			return -EINVAL;
+			goto out_ops;
 		}
 
 	ret = dev->ethtool_ops->set_channels(dev, &channels);