Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3435992imu; Sun, 11 Nov 2018 15:03:49 -0800 (PST) X-Google-Smtp-Source: AJdET5eBWLfKGltkUOP6kfXBnNOe2aa4eIOGEdLepevqasdoJ+qUQRD8lnKOj+LOk+uqLdb1tnnY X-Received: by 2002:a62:fc95:: with SMTP id e143-v6mr17436157pfh.132.1541977429205; Sun, 11 Nov 2018 15:03:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541977429; cv=none; d=google.com; s=arc-20160816; b=QoCcaeXu0ffBT8fFD4kBfS8ctKp2XzPFckxtWxPbCYqpaTlEAwUSd41dWAK5tkTn4B qa49FVv7JWXWXl+a20e/lujm0kkmMahRTpd7nv/6ZoUzp17FHpIA4RpflIwGgITFryi4 +w7ih9EJ9F+8Bf2aNUwcsnL8HpM0FxP77f71qPuFW0WNGIx6TxOBIB85SzAbJ3iViZP9 vWegqrnmJxubTCSSZbiIip7h8ibRwDdmtKVxZEzqp0CUTH/w+GgzOks955jvyx1zFqWG CDYyf195biaZRur/LvJckwStuLXVJJi+HblHw6KhgpJ6PqTxMHo/RSLlHoLLYkiqPIGZ 8PHg== 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=vxPu2+kJrvYm+iLJXkJQc2Ma8tkTzDh2J5ojWI38zGU=; b=YtYhi1LdRmuBJsid8D74nlg2tDd/3NwcUgJ7E4QFnCFcx5khLWNAOtsYqbeZ5uWC55 rwkRwYW6SNw7MjEyaM1rUXN4avy6v/RQYWLvIl24O3aN7fhpVdrYJmBu3eX0teiqPk2I 2+BucZwAM8umWawKGtHOSKdh4kS8vCudZR0biRQo4k+Pho4y5sLthw+e69yDQkB9nGiK 2ZmnQo0MMU2oR7OX62F5xb2Uss37D/NSWQQnVLSHmgD3vKIgQJcg5HjgKheM1AAfTco3 G7HA9OqGQfJrwJSsHCtsnNs9JBscm/HgARDm3o2D/lYkjWL42HQ2Y2CXSLvLUmSEPPNO 4j9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v8E0XGRc; 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 b40-v6si17539120pla.285.2018.11.11.15.03.33; Sun, 11 Nov 2018 15:03:49 -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=v8E0XGRc; 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 S2390583AbeKLIWZ (ORCPT + 99 others); Mon, 12 Nov 2018 03:22:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:52394 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390547AbeKLIWY (ORCPT ); Mon, 12 Nov 2018 03:22:24 -0500 Received: from localhost (unknown [206.108.79.134]) (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 A8C31223CA; Sun, 11 Nov 2018 22:32:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975546; bh=ovGl/xg1nKWPsdWIouxWYeidCRE2VpQi84ZDNvCtmrg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v8E0XGRc/RL8+cKxya3rcJNtFS1ByDMWh3sQMEbCU2DfSwPSowmQXKqw5A3u+OJnH BS4tTyjg+Ycp8Cx2f9hCj1rX6OXOa4QEsnHdopdxTW6mHwhpCDO5q8kiIzRV7Lvkkt SUd0dqNC5eSI2+P2YrI53vRphqReo45Lg83GuyeI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wenwen Wang , Sumit Saxena , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.14 080/222] scsi: megaraid_sas: fix a missing-check bug Date: Sun, 11 Nov 2018 14:22:57 -0800 Message-Id: <20181111221655.208748808@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@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 47db7873136a9c57c45390a53b57019cf73c8259 ] In megasas_mgmt_compat_ioctl_fw(), to handle the structure compat_megasas_iocpacket 'cioc', a user-space structure megasas_iocpacket 'ioc' is allocated before megasas_mgmt_ioctl_fw() is invoked to handle the packet. Since the two data structures have different fields, the data is copied from 'cioc' to 'ioc' field by field. In the copy process, 'sense_ptr' is prepared if the field 'sense_len' is not null, because it will be used in megasas_mgmt_ioctl_fw(). To prepare 'sense_ptr', the user-space data 'ioc->sense_off' and 'cioc->sense_off' are copied and saved to kernel-space variables 'local_sense_off' and 'user_sense_off' respectively. Given that 'ioc->sense_off' is also copied from 'cioc->sense_off', 'local_sense_off' and 'user_sense_off' should have the same value. However, 'cioc' is in the user space and a malicious user can race to change the value of 'cioc->sense_off' after it is copied to 'ioc->sense_off' but before it is copied to 'user_sense_off'. By doing so, the attacker can inject different values into 'local_sense_off' and 'user_sense_off'. This can cause undefined behavior in the following execution, because the two variables are supposed to be same. This patch enforces a check on the two kernel variables 'local_sense_off' and 'user_sense_off' to make sure they are the same after the copy. In case they are not, an error code EINVAL will be returned. Signed-off-by: Wenwen Wang Acked-by: Sumit Saxena Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/megaraid/megaraid_sas_base.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -7361,6 +7361,9 @@ static int megasas_mgmt_compat_ioctl_fw( get_user(user_sense_off, &cioc->sense_off)) return -EFAULT; + if (local_sense_off != user_sense_off) + return -EINVAL; + if (local_sense_len) { void __user **sense_ioc_ptr = (void __user **)((u8 *)((unsigned long)&ioc->frame.raw) + local_sense_off);