Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2520024ybb; Fri, 27 Mar 2020 07:09:24 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvFmeLOoK0e30/CRCR98NouPwo7k8P7wjWOoUqaICybmPhhTLXd27g/rRC3xlm/idQZ6ivg X-Received: by 2002:a4a:e211:: with SMTP id b17mr9257905oot.79.1585318164596; Fri, 27 Mar 2020 07:09:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585318164; cv=none; d=google.com; s=arc-20160816; b=IoZga9zjzPSsrdHijVdH78pG/XUQZq1r/bjAD9QfY/kmU4u59/6EN7UIcE/5KD5nOW B8sAIcnD1oFBZ6ffKOU8HveZawGMRyYeYaKhrKx5cSE1dh9Xa+dnINewSRN9pLwPaQ0f b00+Heunjvibsg24SyT+hGo5stADNZASbzasCXnzwb5ko5teqyMrB0u3OVji9ABJrze3 65gDtfxtg9mSnPUBp7RvHwjIO/hdTVzqkQnjfSpPs4SImA0MvOL3ekNkdq1v/9U5MZZO EAtDxDHR+OUmGkpKPStT+hpNIwWU+0tDVREyDDWXe4K4Q6O6GwYsOwDOz44avChpZ+cV RZ6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id; bh=UWHMllodOCksN+iK9wDy63JJc2nJi/35HFW5+tgzaTk=; b=bt5ZcNXvMujZXHBVaSfGOiebylwhoYhrAg5Hrn8r9J0MmgAnLnmQ7R6MWoovKBG9VB KoVtzWjJWHUKHqj6WpFGcdVcivjKCkPySgVvB3wf/fIzoydrlLQxg1r6Vq32gAqf/5Ya vXc0eZ2K3m09EJ6ZGnhLB9g03CrEiyDaEjpx3m0bfIYYdQ9cxkgAE3sTAl2BMxAOLP4v zKheF+bvxPfUzfPHOasfbuQdjsJDMas7WsZW7kfkP+7VzzpM32BYnGrpB0+sKqwOYSR5 kvG+CN+ZlQxkNy0qxH7Dxpogd6msbOsSADaGavmJiUXswxCjN45f79RbUlOAA3EF8f5J 3yPQ== 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 p203si2529776oic.214.2020.03.27.07.09.11; Fri, 27 Mar 2020 07:09:24 -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 S1727606AbgC0OHZ (ORCPT + 99 others); Fri, 27 Mar 2020 10:07:25 -0400 Received: from mx2.suse.de ([195.135.220.15]:40550 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726333AbgC0OHY (ORCPT ); Fri, 27 Mar 2020 10:07:24 -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 A7A6CACED; Fri, 27 Mar 2020 14:07:22 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id 58246E009C; Fri, 27 Mar 2020 15:07:22 +0100 (CET) Message-Id: In-Reply-To: References: From: Michal Kubecek Subject: [PATCH net-next v2 01/12] ethtool: fix reference leak in ethnl_set_privflags() To: David Miller , Jakub Kicinski , netdev@vger.kernel.org Cc: Jiri Pirko , Andrew Lunn , Florian Fainelli , John Linville , Johannes Berg , Richard Cochran , linux-kernel@vger.kernel.org Date: Fri, 27 Mar 2020 15:07:22 +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. 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: f265d799596a ("ethtool: set device private flags with PRIVFLAGS_SET request") Reported-by: Andrew Lunn Signed-off-by: Michal Kubecek --- net/ethtool/privflags.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/ethtool/privflags.c b/net/ethtool/privflags.c index e8f03b33db9b..77447dceb109 100644 --- a/net/ethtool/privflags.c +++ b/net/ethtool/privflags.c @@ -175,9 +175,10 @@ int ethnl_set_privflags(struct sk_buff *skb, struct genl_info *info) return ret; dev = req_info.dev; ops = dev->ethtool_ops; + ret = -EOPNOTSUPP; if (!ops->get_priv_flags || !ops->set_priv_flags || !ops->get_sset_count || !ops->get_strings) - return -EOPNOTSUPP; + goto out_dev; rtnl_lock(); ret = ethnl_ops_begin(dev); @@ -204,6 +205,7 @@ int ethnl_set_privflags(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