Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2462922imd; Fri, 2 Nov 2018 11:50:36 -0700 (PDT) X-Google-Smtp-Source: AJdET5eQd3JxMKZLnzc2VpwGGegBo4mB+Jx6v4wroMOd19wdKOK3Wf2/lTEhJX4Qs69uJd/8q5R8 X-Received: by 2002:a63:9742:: with SMTP id d2-v6mr12018254pgo.278.1541184636400; Fri, 02 Nov 2018 11:50:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541184636; cv=none; d=google.com; s=arc-20160816; b=oRSS0qNLdCMxva0lbbSIoiD8MaSrrd+LSWb9b5zECQ3p3HlVvGAk7o3KJW+JZh403m 1fL95EO4E/rDn4M4FJ9ofNhXYa74bRC6RrijQ8A5LrSm/FNQmnxfmJp1qCDDEEYFwQFo LeyBM38mSh0oQAH4saIXe0N/OvjX54COsFDlS5p3oACsnk/QtXrLVqK9qfeBJ3mvCDCB ZYomhUJsqN5KXeoBEgXp6jg1g1fIf1mC2qGddFwsvunr75umnw2sYu6EC7NG1PBQCg8e Hzu/hlSO1u+SVk73rBbhp/EeowvY6dEFa86G/XlHIb3Bx2AX9L/UMtP611/fEFF/z3Pf A/Qw== 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=skw+K/EDGHeuBPm8EVrVmJGJwKRCiIowcXiC27LX/rM=; b=mzooOa8+bX3tGWi2Vi+WSqx8qxrcB2JVGjPCxT6LvXC52SbyfaXG++/Eb6lQvp0T9D 1v1HwqD4VdLKL6EkGH5CxKNyNi0pAOkCgzCGJokehfrxrMLZjncopEOJ2cZ9/KRuE+tJ zJoxfJ0cGdCfj++1h+b+jmZ0dBnJ8jNBVBM8ybDX/FXPm2j/i8h0K2fCpEXjPg0fCyLL hOB56i8HsFajU9fxQJTmvCw9YUNlp/gf7Xy8RBKx0q+nagB/dYTi/iq/boVWHX9U54Dm LvEVRuQoPB2+0ljnS9/HHHVcjMAZ5a+Olvj+2b6FZo065x6ggSdTzCcn98NCYuzZFuO2 KY5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cfsXIz65; 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.50.21; Fri, 02 Nov 2018 11:50:36 -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=cfsXIz65; 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 S1730754AbeKCD6P (ORCPT + 99 others); Fri, 2 Nov 2018 23:58:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:54030 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728280AbeKCD6P (ORCPT ); Fri, 2 Nov 2018 23:58:15 -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 53A092082D; Fri, 2 Nov 2018 18:50:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541184600; bh=DSErnt+Ryc0Wp94KBDjSiCjCAGOcnzM5s2jdJCFCjZw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cfsXIz658wMeBwjKTpgrhcBBBjwmB8xrkG8LRy6bpyog3S1eInK40qvBMVUfhAcmu CP85wbWDsBbRUcO0R25vNqcCW7RZMmhj7MRPRwLF7I74tvrMGKalZROqbro5l3jeLR 5cGcrTz+g9rL0rBMJ2fYFnCdPk35pqLHnHEyHz6Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wenwen Wang , "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 047/143] net: cxgb3_main: fix a missing-check bug Date: Fri, 2 Nov 2018 19:33:52 +0100 Message-Id: <20181102182900.831506229@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. ------------------ [ Upstream commit 2c05d88818ab6571816b93edce4d53703870d7ae ] In cxgb_extension_ioctl(), the command of the ioctl is firstly copied from the user-space buffer 'useraddr' to 'cmd' and checked through the switch statement. If the command is not as expected, an error code EOPNOTSUPP is returned. In the following execution, i.e., the cases of the switch statement, the whole buffer of 'useraddr' is copied again to a specific data structure, according to what kind of command is requested. However, after the second copy, there is no re-check on the newly-copied command. Given that the buffer 'useraddr' is in the user space, a malicious user can race to change the command between the two copies. By doing so, the attacker can supply malicious data to the kernel and cause undefined behavior. This patch adds a re-check in each case of the switch statement if there is a second copy in that case, to re-check whether the command obtained in the second copy is the same as the one in the first copy. If not, an error code EINVAL is returned. Signed-off-by: Wenwen Wang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c index bf291e90cdb0..79053d2ce7a3 100644 --- a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c +++ b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c @@ -2159,6 +2159,8 @@ static int cxgb_extension_ioctl(struct net_device *dev, void __user *useraddr) return -EPERM; if (copy_from_user(&t, useraddr, sizeof(t))) return -EFAULT; + if (t.cmd != CHELSIO_SET_QSET_PARAMS) + return -EINVAL; if (t.qset_idx >= SGE_QSETS) return -EINVAL; if (!in_range(t.intr_lat, 0, M_NEWTIMER) || @@ -2258,6 +2260,9 @@ static int cxgb_extension_ioctl(struct net_device *dev, void __user *useraddr) if (copy_from_user(&t, useraddr, sizeof(t))) return -EFAULT; + if (t.cmd != CHELSIO_GET_QSET_PARAMS) + return -EINVAL; + /* Display qsets for all ports when offload enabled */ if (test_bit(OFFLOAD_DEVMAP_BIT, &adapter->open_device_map)) { q1 = 0; @@ -2303,6 +2308,8 @@ static int cxgb_extension_ioctl(struct net_device *dev, void __user *useraddr) return -EBUSY; if (copy_from_user(&edata, useraddr, sizeof(edata))) return -EFAULT; + if (edata.cmd != CHELSIO_SET_QSET_NUM) + return -EINVAL; if (edata.val < 1 || (edata.val > 1 && !(adapter->flags & USING_MSIX))) return -EINVAL; @@ -2343,6 +2350,8 @@ static int cxgb_extension_ioctl(struct net_device *dev, void __user *useraddr) return -EPERM; if (copy_from_user(&t, useraddr, sizeof(t))) return -EFAULT; + if (t.cmd != CHELSIO_LOAD_FW) + return -EINVAL; /* Check t.len sanity ? */ fw_data = memdup_user(useraddr + sizeof(t), t.len); if (IS_ERR(fw_data)) @@ -2366,6 +2375,8 @@ static int cxgb_extension_ioctl(struct net_device *dev, void __user *useraddr) return -EBUSY; if (copy_from_user(&m, useraddr, sizeof(m))) return -EFAULT; + if (m.cmd != CHELSIO_SETMTUTAB) + return -EINVAL; if (m.nmtus != NMTUS) return -EINVAL; if (m.mtus[0] < 81) /* accommodate SACK */ @@ -2407,6 +2418,8 @@ static int cxgb_extension_ioctl(struct net_device *dev, void __user *useraddr) return -EBUSY; if (copy_from_user(&m, useraddr, sizeof(m))) return -EFAULT; + if (m.cmd != CHELSIO_SET_PM) + return -EINVAL; if (!is_power_of_2(m.rx_pg_sz) || !is_power_of_2(m.tx_pg_sz)) return -EINVAL; /* not power of 2 */ @@ -2440,6 +2453,8 @@ static int cxgb_extension_ioctl(struct net_device *dev, void __user *useraddr) return -EIO; /* need the memory controllers */ if (copy_from_user(&t, useraddr, sizeof(t))) return -EFAULT; + if (t.cmd != CHELSIO_GET_MEM) + return -EINVAL; if ((t.addr & 7) || (t.len & 7)) return -EINVAL; if (t.mem_id == MEM_CM) @@ -2492,6 +2507,8 @@ static int cxgb_extension_ioctl(struct net_device *dev, void __user *useraddr) return -EAGAIN; if (copy_from_user(&t, useraddr, sizeof(t))) return -EFAULT; + if (t.cmd != CHELSIO_SET_TRACE_FILTER) + return -EINVAL; tp = (const struct trace_params *)&t.sip; if (t.config_tx) -- 2.17.1