Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp27211imu; Thu, 8 Nov 2018 14:08:35 -0800 (PST) X-Google-Smtp-Source: AJdET5fh4NzJQRvzRF3t1iqoGq35sT3rREjOT1i3kTyavaQoZ0S9JfQ8PXxJR3SjYy9FQciLxlBj X-Received: by 2002:a17:902:544:: with SMTP id 62-v6mr5989651plf.73.1541714915846; Thu, 08 Nov 2018 14:08:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541714915; cv=none; d=google.com; s=arc-20160816; b=DeCaxdWgBjl3vlhBWQ3UeXKEAhrEIwxZZfROp+ahNdhIFyMU6gHxq2jT7c/u5aYimH ekCeZoBjM0OMXEJMIl4tSmo/6gwjFvVbGBtSrCKiaePHKNiOcH5mfG4kFCRvNnGISypF HhFbDY1XMEtT2Tx66oLCpM7a9PVujEaVrmyQ4RXcdLYYaCKdXB33baQ+kwDJOigyM1HL jhcwNBB+Glb2Hk87gMhaJzW6d+qyMmycZzyo/UCutCi2hLxXOxylioWFa2Pjy7Eu4BO/ cVtH7396V2AOR4tNJWpJ9ATayXOBO9HKLuiAOraHoxsYhnuQ8iRWrKh6VVL9Smy+PrgQ UAuA== 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=C1eO/PvLTMRvbBBHyUG7LBui3NeTAxjFkZG+OQ+xfI8=; b=Au6XT5dv/fcO3HHHCvl/zC3HErznNgwK/kbbunQ74Wu4U3qLnerKHzn4hRqwnFgVJO ZQcTo4OjU8d073HPqpx4jZcg6ayLMRrmqwyqfFGYFjXYucfdUTQYw3rhIF+hYFKVlDYQ MolM9HnUAu3ZvoEs6jIPOTvfhQTu5o02TL2W7fjbCSd19Aw+46iHeo5duOm1Knt/e6/A w3yx8PSznfjEi1lPv+PyUHR4mRJn3EgXJSdjxFWQF5u5xBgyK63DAVQ+eesGsrAVIzLr PoUdqZu9PuhxfwJSdeJuSWuFOGad89NTd0GxlZoTgakO7B+JEc2sqkcRSBHK0uzP3ZcH e08w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HDhKBL6x; 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 d4-v6si5375719pla.203.2018.11.08.14.08.19; Thu, 08 Nov 2018 14:08:35 -0800 (PST) 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=HDhKBL6x; 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 S1732095AbeKIHoW (ORCPT + 99 others); Fri, 9 Nov 2018 02:44:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:37246 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730843AbeKIHoW (ORCPT ); Fri, 9 Nov 2018 02:44:22 -0500 Received: from localhost (unknown [208.72.13.198]) (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 5A85120844; Thu, 8 Nov 2018 22:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541714811; bh=gzzqo2fg97zmKuKcljRD8b+TcYR/wJYKfAESqOoUXlU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HDhKBL6xUSoPeJHa3l3MGklGGOyjRExOwpyzB6AHSbJwB2eV3Z82bm4cq1TooDi9i gibRITEfIxJJXO0gzAweJQYJMxD11FaqbSDeUehDqgMpT15CztJlnXVA+aETqm6SO0 mkzhJX3Yx4VQMT1zZqE4niImSXoLYX8znmdpFZt0= 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.9 141/171] net: socket: fix a missing-check bug Date: Thu, 8 Nov 2018 13:51:51 -0800 Message-Id: <20181108215137.187831317@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108215127.257643509@linuxfoundation.org> References: <20181108215127.257643509@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.9-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 @@ -2774,9 +2774,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; }