Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3020194ybb; Sun, 22 Mar 2020 13:17:45 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtw5fhAqcYfK0B8cRyxHS4lQvkDCJWiBOSt2QE1i4tj2elZbvfXgeV2QvkfQ7UAHGkdBT9R X-Received: by 2002:a54:4181:: with SMTP id 1mr14764983oiy.158.1584908264927; Sun, 22 Mar 2020 13:17:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584908264; cv=none; d=google.com; s=arc-20160816; b=JzYzmNkZXvLhNwADiBcBn3ao1l1BW0/524/1U9Ce7GpU4FMWvaGA5zIKPXzTtg4Hes sUHzdGxzNR0IlcRMAbSaQmO9/Bc/yKohMeZq9z6vpB00tEv1M1hBlo2Ht7v8sKZINg2O HLeqa7WNTP5nm8arC3Z18PM9W1msMgHM+7sIPw9Ng2T2ho/obqx4Z7eAng7SfqaLwtNv 7+1nK1uzvPq5esBOBjOfWFnC89POj5zTVHUcBLTDEFUhhi1Fwf1wvrizsufckqsEMJjn KIQmqge+zPDvuyWIwg7hkJq+krvb2u8yukokZPsGRMm6Wk2UXy0Varl+DUvTfgQ60lIK MQcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:message-id:cc:to:subject:from; bh=H/XxL8vYTQY1/6uJ+U1Dj1lMas+xPO23UYPzTagt9zg=; b=I2/6zcTncp63kUlTRgbdSex7UZ+02TD7SGEkQnqWobB7gU4JtPbQ1BOIJKHoJdeBBN AJ1Ht2YXNqQs81zZZUxwd489qYGFkYU5CvbePEnmCUhQc22U6BItH7p08TJUdkNXtWRD J037KST94kVK+AGRI+KryrS1bn0xTqAEceCr9rbJ1HwiZ6WvmYUzBaZEUXyiQtkKxjfZ QWLNLtxtOEScWEx5LHdJSApgJwSqhELx/wlWapFC+qFpGVIgPcmzlZGEpAkjIDVVwxnk wdVDuHBO3S5y7fUMFpzpBc5qJSNZlxKru5wzDBPLDNcBYhuT9+E/5hrq4TCI7FuyQG+b 29DQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m81si6386661oig.190.2020.03.22.13.16.51; Sun, 22 Mar 2020 13:17:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726786AbgCVUPz (ORCPT + 99 others); Sun, 22 Mar 2020 16:15:55 -0400 Received: from mx2.suse.de ([195.135.220.15]:42990 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726623AbgCVUPz (ORCPT ); Sun, 22 Mar 2020 16:15:55 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id DFBABAC92; Sun, 22 Mar 2020 20:15:52 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id E11BAE0FD3; Sun, 22 Mar 2020 21:15:51 +0100 (CET) From: Michal Kubecek Subject: [PATCH net] ethtool: fix reference leak in some *_SET handlers To: "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org Cc: Andrew Lunn , linux-kernel@vger.kernel.org Message-Id: <20200322201551.E11BAE0FD3@unicorn.suse.cz> Date: Sun, 22 Mar 2020 21:15:51 +0100 (CET) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Reported-by: Andrew Lunn Signed-off-by: Michal Kubecek --- 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(-) diff --git a/net/ethtool/debug.c b/net/ethtool/debug.c index aaef4843e6ba..92599ad7b3c2 100644 --- a/net/ethtool/debug.c +++ b/net/ethtool/debug.c @@ -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; } diff --git a/net/ethtool/linkinfo.c b/net/ethtool/linkinfo.c index 5d16cb4e8693..6e9e0b590bb5 100644 --- a/net/ethtool/linkinfo.c +++ b/net/ethtool/linkinfo.c @@ -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; } diff --git a/net/ethtool/linkmodes.c b/net/ethtool/linkmodes.c index 96f20be64553..18cc37be2d9c 100644 --- a/net/ethtool/linkmodes.c +++ b/net/ethtool/linkmodes.c @@ -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; } diff --git a/net/ethtool/wol.c b/net/ethtool/wol.c index e1b8a65b64c4..55e1ecaaf739 100644 --- a/net/ethtool/wol.c +++ b/net/ethtool/wol.c @@ -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; } -- 2.25.1