Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp172533imd; Wed, 31 Oct 2018 16:46:51 -0700 (PDT) X-Google-Smtp-Source: AJdET5eZTjy4ObH9PbCPYn/StzT/TRsMW+cvRkk4aDLr5MOwbjLTdZv+EkKSIPAS/aNbAkexbzLT X-Received: by 2002:a17:902:b943:: with SMTP id h3-v6mr5092083pls.124.1541029611131; Wed, 31 Oct 2018 16:46:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029611; cv=none; d=google.com; s=arc-20160816; b=sO/iJDI6laR5hAYvpTph7PFMLjyxFsluhBzJUjvMEmu+0AtXYrYV+RwKy+3LSZgm6d pSB42NZX/J5a2eKbkqV5JXFJM7q83JKxOJ3LcNpwIW+eUydDIq32DQ1x41tDRxdDiyUn pKR4ALbYaePndmJEP1pKyLb4IwvpSxyJvTlXF43PF+xiU3QUUnNf1cfNtd5Tf40rYB8y irFnPn7RlRUxK1tXlpNwTVpRzpYnzu7SnlTBLZpZ2m1u8k5czchD9Uw153AyHj9C5YwV QMAjYK6QLVQGvtxokvQpxrMFof3p1VSeXB4VvcHpF+Pm2Yjs9mnEC0XDJSMR8JdLayLj t0SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=QyKeJxOQoqDCGJ4uw5+Pyu5yzczropECl7D61cbEKs8=; b=Dm1cdN+X18p4dfgq/skF/yXc94VMAgMtjBz0GmOkFZ7UEtlO+os9W6mQgMFuaziIGo APqrKYZON2rOGo7VDTsO0vG7jnVyDSl/Bgq7p45kCmaNPte5Eu7zwm6QyQTZQidVQSPS bQheebTE+dCSyBQmexispZ6fEjXelFhID1eF+AxQyHo2kb8BgqVichP2LszJ5MsA8Ny9 c6u0Yrd0pzOMKIqBsQGH+R58zKAXhl4Jklp0InNxyiXoOgqdonAPigsYRujpQtxtiakH AGI5hoj5e8TF3M8zgLGOHK1l/NrbfsXImuLyXWidliN/lX6ZIJYo02cLspVq/NoGbp4U wZQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=buj2rQch; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k198-v6si31123267pga.12.2018.10.31.16.46.36; Wed, 31 Oct 2018 16:46:51 -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=buj2rQch; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728998AbeKAIq3 (ORCPT + 99 others); Thu, 1 Nov 2018 04:46:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:55012 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728784AbeKAIHU (ORCPT ); Thu, 1 Nov 2018 04:07:20 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DC32D20821; Wed, 31 Oct 2018 23:07:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027229; bh=tEXz/++tMGKHr86NZqpb8GAUuYfZPpJ2ks7AzX/qbNI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=buj2rQchKu+grc8Tc5RuOMGnKJp1CvlPmsgmSyQ3U6XHOIVH+GpxzlmmC64b5IzRm HtGf9bbL925NdLTBTGzjnlT9+Nr1pBcI1MMspL+SPDOjPCBIFYnFrV1QcwBsM4tqnn O3R+YnCc042BjRq1eEN88RDvGirkWc14bx80C5as= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Wenwen Wang , "Martin K . Petersen" , Sasha Levin Subject: [PATCH AUTOSEL 4.19 096/146] scsi: megaraid_sas: fix a missing-check bug Date: Wed, 31 Oct 2018 19:04:51 -0400 Message-Id: <20181031230541.28822-96-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/scsi/megaraid/megaraid_sas_base.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c index 9aa9590c5373..f6de7526ded5 100644 --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -7523,6 +7523,9 @@ static int megasas_mgmt_compat_ioctl_fw(struct file *file, unsigned long arg) 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); -- 2.17.1