Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2460279imd; Fri, 2 Nov 2018 11:47:30 -0700 (PDT) X-Google-Smtp-Source: AJdET5do0hKwFNHvG+Xm65CtdhsAW3YM4FT5vmPQ1h2LFIZ8q5A8HLPfx49ewqtq7d4hY96mt+nq X-Received: by 2002:a63:4d:: with SMTP id 74mr9399123pga.248.1541184450393; Fri, 02 Nov 2018 11:47:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541184450; cv=none; d=google.com; s=arc-20160816; b=eHtHcQeuJlx8hEFLX8W51kpZaxPX0d0nFU+x0fjjcUW0Mnb5tE0r6kCycytYgijSE/ fgLmXaWAVYKZjISEc2oIuPAHkIFJQzfPPLKCEetMBLIMRA5BT4fGge+g9amRgHhsWtB1 az6giHMy/v3Mo5DmqqH7zPs6aXSSs5wAhI0SYLX7TTDiUg1TLJxVlbIrXPBxG5Ep10uR nP5OXEvN288HVhsoiVmekvWM2FBrfKHuAOlqfOdUKtQUxWDQtJKEyHpVB0B+ggyCnQlB 3nyhznpxWMi2DRDXMf5hUxGvAEd0Qp7txdg8LVrMIZnpPZV9uURztxxp6ISQFllFB1kf Ilwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rPKUhcXk7N0Aski9NOaePDoSwnKTEAolqopwrbboCqE=; b=Yed9bmkTlmGTCiGawHu26/2Ep7Ya4yGc6A2XhrkFJjeJNpRLBDC32QrjDHmWL+kwd7 O5JZMVlpOjKCNHZmbgTLEb7FUT1prkC4rwSu97NS8v6KlgwbnnQLjh+v5ooq71S1+Wco 9EvOGEQrmx8KN+S3qZEZtyjeqpE18uTHhdIS9IB5iH6aPz7bEgzRUOoe5gAmXgcOXhu2 ix36cuUos5I3Cp5706Wxu7Vps1iclvZH8TBOv3iHYrQUlxign2KCuRfFvIIdj4V7M9JQ At7w8s2kzMk3xVCS9lsygkLtdIIAsIvmHha5Sfb9RzbBypwDCX3mENKZxEc3APLTdMjA 7D1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=j7wJ1C3i; 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 m123-v6si20365600pfd.112.2018.11.02.11.47.15; Fri, 02 Nov 2018 11:47:30 -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; dkim=pass header.i=@kernel.org header.s=default header.b=j7wJ1C3i; 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 S1730400AbeKCDyn (ORCPT + 99 others); Fri, 2 Nov 2018 23:54:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:50668 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729136AbeKCDym (ORCPT ); Fri, 2 Nov 2018 23:54:42 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D924C20837; Fri, 2 Nov 2018 18:46:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541184388; bh=0Dk52O5XdnEzfKIO8JEer6a0RbZ1yo8FwJ1bJ7rQWtI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j7wJ1C3iati1TVojG/9Y8U9Wp13yiwNsHVNWcjSB1zILhQF0c63oVnyY+oPLlSbwl Ay5Q3+jrHLlj61ZUdWlR6jA2sQ9B295ZOABRQLqUkd7pJiUnX1Ys5bB8UAytup4MSd +8b9bsX/6Zty9g3EkAEFgFwYrC9Mxa1VEbltITjE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wenwen Wang , Michal Kubecek , "David S. Miller" Subject: [PATCH 4.18 122/150] ethtool: fix a privilege escalation bug Date: Fri, 2 Nov 2018 19:34:44 +0100 Message-Id: <20181102182911.454589845@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181102182902.250560510@linuxfoundation.org> References: <20181102182902.250560510@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wenwen Wang [ Upstream commit 58f5bbe331c566f49c9559568f982202a278aa78 ] In dev_ethtool(), the eth command 'ethcmd' is firstly copied from the use-space buffer 'useraddr' and checked to see whether it is ETHTOOL_PERQUEUE. If yes, the sub-command 'sub_cmd' is further copied from the user space. Otherwise, 'sub_cmd' is the same as 'ethcmd'. Next, according to 'sub_cmd', a permission check is enforced through the function ns_capable(). For example, the permission check is required if 'sub_cmd' is ETHTOOL_SCOALESCE, but it is not necessary if 'sub_cmd' is ETHTOOL_GCOALESCE, as suggested in the comment "Allow some commands to be done by anyone". The following execution invokes different handlers according to 'ethcmd'. Specifically, if 'ethcmd' is ETHTOOL_PERQUEUE, ethtool_set_per_queue() is called. In ethtool_set_per_queue(), the kernel object 'per_queue_opt' is copied again from the user-space buffer 'useraddr' and 'per_queue_opt.sub_command' is used to determine which operation should be performed. Given that the buffer 'useraddr' is in the user space, a malicious user can race to change the sub-command between the two copies. In particular, the attacker can supply ETHTOOL_PERQUEUE and ETHTOOL_GCOALESCE to bypass the permission check in dev_ethtool(). Then before ethtool_set_per_queue() is called, the attacker changes ETHTOOL_GCOALESCE to ETHTOOL_SCOALESCE. In this way, the attacker can bypass the permission check and execute ETHTOOL_SCOALESCE. This patch enforces a check in ethtool_set_per_queue() after the second copy from 'useraddr'. If the sub-command is different from the one obtained in the first copy in dev_ethtool(), an error code EINVAL will be returned. Fixes: f38d138a7da6 ("net/ethtool: support set coalesce per queue") Signed-off-by: Wenwen Wang Reviewed-by: Michal Kubecek Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/core/ethtool.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -2461,13 +2461,17 @@ roll_back: return ret; } -static int ethtool_set_per_queue(struct net_device *dev, void __user *useraddr) +static int ethtool_set_per_queue(struct net_device *dev, + void __user *useraddr, u32 sub_cmd) { struct ethtool_per_queue_op per_queue_opt; if (copy_from_user(&per_queue_opt, useraddr, sizeof(per_queue_opt))) return -EFAULT; + if (per_queue_opt.sub_command != sub_cmd) + return -EINVAL; + switch (per_queue_opt.sub_command) { case ETHTOOL_GCOALESCE: return ethtool_get_per_queue_coalesce(dev, useraddr, &per_queue_opt); @@ -2838,7 +2842,7 @@ int dev_ethtool(struct net *net, struct rc = ethtool_get_phy_stats(dev, useraddr); break; case ETHTOOL_PERQUEUE: - rc = ethtool_set_per_queue(dev, useraddr); + rc = ethtool_set_per_queue(dev, useraddr, sub_cmd); break; case ETHTOOL_GLINKSETTINGS: rc = ethtool_get_link_ksettings(dev, useraddr);