Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp47692imu; Thu, 8 Nov 2018 14:31:57 -0800 (PST) X-Google-Smtp-Source: AJdET5elIBTnLm3FbdvU/Eb3XkJ4CvkQ3zx0D+hCH3xlQqSDoEjN/5IWAgsE7SCcn2cVTF4hZ+uG X-Received: by 2002:a62:4301:: with SMTP id q1-v6mr6251911pfa.163.1541716317607; Thu, 08 Nov 2018 14:31:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541716317; cv=none; d=google.com; s=arc-20160816; b=mP07fClwb9WR6MZM6l9xdbWvQ9N7giANl7uXnV0cyPPFuZwy62RRtUokvu+bGING+M oOLXAee8+xWOTbcUDGdgTP55uCNd41YLS38Bl2Hw3XU+PRQiGixb1lOXRttdYPhcLiIT 08sTKAf776N1qbD7EPYYlNZQv1+BfK0+sEFbsuDYJvs3QHHl1bn/A1rKNDi+ioNaRU4t mBgSwPdrNQQ8wF30FCKU7FHP/cv+kHyUBe6fpqSRNQ9TlOTPMGHq/iNW/Lnp+c+b5n49 vibtSvrkVG0vgFQfBk2Bx3yiAp1QwrBqdw03SShqsl8JMS6ojw0q8SN8aoG4IDr/Y9lX 2E2g== 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=J2xLGvWfA0uS++hs4vxK45fZfrinAD15QnO3iSWy8dE=; b=NbURoe4E0IytP+D+sQLqEaI2GiSNI1aPucvLB56xg7dyVobPnbQaRrkRlM9wFoLhNo xQCwd0V3BgrQ66U4xTC+YlH6KlNUJQsnXsUwEvJMKFiW2U3JORwTT2vXSuEKXfN65X5W TDWJfIVbzsE+ojUSH2oxbi3oOglVkErFIJFombelcteCIctZmxjrL1n+Ue6MM0ll+ns2 To+CQT7LdJ6JDgMUZIg0s0t6lxqS2Mei3/gR4eGALhkuIez7Rk4E4g+U+qpzlWtIMV+5 IaVmiZQ8yuu+BncpJDqOY7nCaFFisTBc4I++ecJZYVEwn4WMEWeV0I5o0gwNYo7KExlo ZNLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=keHVOWJC; 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 a61-v6si5990365pla.430.2018.11.08.14.31.42; Thu, 08 Nov 2018 14:31:57 -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=keHVOWJC; 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 S1730647AbeKIHiP (ORCPT + 99 others); Fri, 9 Nov 2018 02:38:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:57354 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729667AbeKIHiO (ORCPT ); Fri, 9 Nov 2018 02:38:14 -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 D13C220818; Thu, 8 Nov 2018 22:00:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541714445; bh=Y3fJzWKO3qrWXZ6rES3XdvDFYl1UGAwMg1O7LXo7G0o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=keHVOWJCfGYJK9+J1GepHEs5h+zn/M1Ix7GkHMeGaU1R9189aZol8rZJEEEoK1/HE g9aVGnCmbxKhrgY+AcLME9CiYDcYn75vDlL4V+PaAvsyatqg7S3zP9cznZQnfH8box p+J/NogIpEQDJyF+eN/9Uue6dSU5JoP97Llz0PkE= 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.4 094/114] net: socket: fix a missing-check bug Date: Thu, 8 Nov 2018 13:51:49 -0800 Message-Id: <20181108215109.246382179@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108215059.051093652@linuxfoundation.org> References: <20181108215059.051093652@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.4-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 @@ -2760,9 +2760,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; }