Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2468344imd; Fri, 2 Nov 2018 11:56:51 -0700 (PDT) X-Google-Smtp-Source: AJdET5eVB1LEheA+zKd66k7C/B8LLhTMS6zXTQbtR4CuI/QJt8MlWO+PEK/cSbQCqRXNIseiF/cq X-Received: by 2002:a17:902:7146:: with SMTP id u6-v6mr12456336plm.322.1541185011274; Fri, 02 Nov 2018 11:56:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541185011; cv=none; d=google.com; s=arc-20160816; b=qaa7Pglm2KlMbhXS6UaZUzPLcGdSPyEClJXX47w6WwwLscYraEMHss/pvTwV4MgP0L 5KqVeKn6RWpYlnWLTEje+VrccOkmEmmNe7N4IlXo95REYpsYxnuOBxhYMCeqbkXPu/OS p7ssOMg8hPeH519QHqEi3NcVvmhe1+COVvydjcXOgNbRwh6562H7rIp67MEtvwpQ0q7A u3Io/i8reA0Yva1nfsTfzJRsM+SyhXLOgSNAtW6k3X3od7NUySPsenKfz6TrO2SrnahY c/clsIvN3zUM/SINGZnDpnYfflcXz+KL7YA6rUOM0FrbyZRb81M0tD4OeLasBSHmxUt/ UiIA== 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=oESUChTCGdSVwXMmYVjNrHSMpSJW3x9WhkcHh4tNROM=; b=TPtebAVhqA0gQBfqRxiyTulRG4WyVNhebFUVBGpdv7I5jUv7AVsVIwauAfNKybI5jh 54qqk17KpatTM4PcIVFzUeMJaZ8PZbpBtt6rpREzOju3AhV7LGcyAMTNJy1Bc0FYZd9J PgbsdNgExUelqlsC+V6qCcaw00ylHnUmdRfsAWSNpJa0qRyrhGcIqbsWTsvM1saMxgwO jdzsgdjQaqdD4zx8RSOCIekPty17Y8tPTjfpiNlCvN0L0XJO49IXqVE5+07CcJU8UA1a BahtRQLitUmblJiDuZgrcCFiDVtiJslwTqgZCRK9HXcwj9WTSafJaXZDLBRhURYAw2Hr mGTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="tfmG8/iM"; 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 b12-v6si4465039plr.175.2018.11.02.11.56.37; Fri, 02 Nov 2018 11:56:51 -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="tfmG8/iM"; 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 S1731303AbeKCEDO (ORCPT + 99 others); Sat, 3 Nov 2018 00:03:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:59014 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726760AbeKCEDN (ORCPT ); Sat, 3 Nov 2018 00:03:13 -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 2AB842082D; Fri, 2 Nov 2018 18:54:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541184897; bh=tZUbq+SL0VyzUkgTGTXqzVO9JfG/wHoalXL+094K8Ho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tfmG8/iM8SR1Sdf41FUy+IlDgQIgMwv0kkEDWU0injIeOUAbmvJ7UtmjUtAVssyik wyyayLtfYyfpZ2HTVYL9HqrWNPa004Hwe/LAdvXHxRzKFmAilcd1p9YdQN8YVu1WsA Wl0+eHNPFyL+BVYrbMkdWLBlrOIxCBzhgxvLdw/k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wenwen Wang , "David S. Miller" Subject: [PATCH 4.14 123/143] net: socket: fix a missing-check bug Date: Fri, 2 Nov 2018 19:35:08 +0100 Message-Id: <20181102182907.693174080@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181102182857.064326086@linuxfoundation.org> References: <20181102182857.064326086@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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wenwen Wang [ Upstream commit b6168562c8ce2bd5a30e213021650422e08764dc ] In ethtool_ioctl(), the ioctl command 'ethcmd' is checked through a switch statement to see whether it is necessary to pre-process the ethtool structure, because, as mentioned in the comment, the structure ethtool_rxnfc is defined with padding. If yes, a user-space buffer 'rxnfc' is allocated through compat_alloc_user_space(). One thing to note here is that, if 'ethcmd' is ETHTOOL_GRXCLSRLALL, the size of the buffer 'rxnfc' is partially determined by 'rule_cnt', which is actually acquired from the user-space buffer 'compat_rxnfc', i.e., 'compat_rxnfc->rule_cnt', through get_user(). After 'rxnfc' is allocated, the data in the original user-space buffer 'compat_rxnfc' is then copied to 'rxnfc' through copy_in_user(), including the 'rule_cnt' field. However, after this copy, no check is re-enforced on 'rxnfc->rule_cnt'. So it is possible that a malicious user race to change the value in the 'compat_rxnfc->rule_cnt' between these two copies. Through this way, the attacker can bypass the previous check on 'rule_cnt' and inject malicious data. This can cause undefined behavior of the kernel and introduce potential security risk. This patch avoids the above issue via copying the value acquired by get_user() to 'rxnfc->rule_cn', if 'ethcmd' is ETHTOOL_GRXCLSRLALL. Signed-off-by: Wenwen Wang Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/socket.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) --- a/net/socket.c +++ b/net/socket.c @@ -2879,9 +2879,14 @@ static int ethtool_ioctl(struct net *net copy_in_user(&rxnfc->fs.ring_cookie, &compat_rxnfc->fs.ring_cookie, (void __user *)(&rxnfc->fs.location + 1) - - (void __user *)&rxnfc->fs.ring_cookie) || - copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt, - sizeof(rxnfc->rule_cnt))) + (void __user *)&rxnfc->fs.ring_cookie)) + return -EFAULT; + if (ethcmd == ETHTOOL_GRXCLSRLALL) { + if (put_user(rule_cnt, &rxnfc->rule_cnt)) + return -EFAULT; + } else if (copy_in_user(&rxnfc->rule_cnt, + &compat_rxnfc->rule_cnt, + sizeof(rxnfc->rule_cnt))) return -EFAULT; }