Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2458465imd; Fri, 2 Nov 2018 11:45:24 -0700 (PDT) X-Google-Smtp-Source: AJdET5cQ1lLJSxRrDY2rjeZFa5OTgZPv/mYRdIB0WXpG3cBh8i8vGYRmXeLOYQ501/cxcZOD64Le X-Received: by 2002:a63:6045:: with SMTP id u66mr11979458pgb.204.1541184324007; Fri, 02 Nov 2018 11:45:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541184323; cv=none; d=google.com; s=arc-20160816; b=auSfXj2nGtYQMbacDKMWLroAq5ANrloHa81gdB7SQAU9mfDLGNUgd56GDD2oxAG48H B03LCpDUSGOHEhkNKxlAIxNfC31sV3iSF2M/tU78I7v5ClBv5MRMy1zxKF+6eZneTgil PQUHSXBXyaPS5MvzscxZIL9d/S6H4psKBJfNRzTxWQ5w6OaMs7sIhRDcQ87YowvAWWzE soFdgMTpIf8JoNAomRPz0Jy0JiOIdS2Ds1KJhTjrcN+VnDM1k+rQh4lLshTWOa05LTWJ ejhrM8CSRgO3aKxf53PBiWQ/MfIszJSur1vV/K5mpDStNsl1DVhYp2edhMY/d4Bm2ong SITQ== 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=Ghs0G4mWt7zfmS2aW+k2ZVzHvaShb0pOMWUKTARDAkw=; b=MDJVnL8h3Cd2ULPdSUeAkuCGEAJLQAsgRTthlUD7q7K5BAoGYwdMfJ0+mFSXy0zkzL +4xvgasdn4SPc9PRMh+FqKJ3Gyac1afFE+TWIuXyf0K92xUzKmM4xq5+UADko6X4R2g1 L20TShtVShHt0qbmapKeujAKIjfi+aNkZTlyIzEfqri6ShUQOyDwBGumQuDoxkNSpvxl gcjY6LePvNcpd/KQRXwSnptfXT3ZO2ot1P8HNyF5vP6MvsRfsjv9hgHsrugQQiAQ7tHU c5uOpHp+RIjCfxgCdwh5CH9VOvDIMNa4PqMGWjwPRLx0okGaYOwxbbqG7VpkGArv2gtt 0oSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jCaE57aP; 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 z7-v6si34337156pgc.343.2018.11.02.11.45.09; Fri, 02 Nov 2018 11:45:23 -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=jCaE57aP; 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 S1729996AbeKCDwL (ORCPT + 99 others); Fri, 2 Nov 2018 23:52:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:47456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726849AbeKCDwK (ORCPT ); Fri, 2 Nov 2018 23:52:10 -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 4456220847; Fri, 2 Nov 2018 18:43:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541184237; bh=dpZkfPrg9larV5EtNTu1msmcHHQKvRGZW63YcXvCjSU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jCaE57aPTPJDqnua7+gB17r+c5KKTQAhf/jGNmMVKNk0pzMwu4YIx9NEV3pAr7o05 VMEWvgCzkJvLheUW8OhJDejmbHo4ub7Xhl8DAY+dvxz9lzOJgbPKBEkFUCphEw+pPz sMtGF9xrDcfLk0TFzYQ2iCmNeAbjPAUm5hI39Rm8= 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.18 112/150] net: socket: fix a missing-check bug Date: Fri, 2 Nov 2018 19:34:34 +0100 Message-Id: <20181102182910.978994735@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 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 @@ -2887,9 +2887,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; }