Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3480943imu; Sun, 11 Nov 2018 16:04:53 -0800 (PST) X-Google-Smtp-Source: AJdET5f0CKhzM6VDLE+26M4hmy2Lvk+U2WpkemcnC7AjErUUTw4dDLF3gEAlJQSapwGsP15Gsa69 X-Received: by 2002:a63:3204:: with SMTP id y4mr15476653pgy.41.1541981093416; Sun, 11 Nov 2018 16:04:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981093; cv=none; d=google.com; s=arc-20160816; b=bbpwg/MergPTgke0lBv9J8QjVTzqGrzQmi4f3dXCAXwbs9Sy5odrF0fhjgU1O/SF9c A12mZ9t1v62X6d8ADAQDqgYqzCknNcZmd+zwAwPzH9BHSPqlaiPp4+1/hfF4KdI3RfXm 8XkBNpWGKvb4JegbvhqGgpK5V4F8SaQ3k2wE34dgy0rDvU3tpzd0qad9cmfpaSjSuebB XGqmu0VmvLHX3iTli+jYwKfnpp2COb1x4xWDcFmm0xLxwZ/Se1t4oTveyVX1oI+jvwJn Aq5RUmReyeDjNAqtexSRt8N+4qAFWeuA3O2ikNI3c54GLRWuYfT6aDqPGrndOl8n+aEG UgRQ== 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=QHFTFZaPzmzVcLyH6K0i72Hjkm79zz7gWeFfZLvP8JM=; b=Ogl6mEBvd5838oM2yaLOkRmU4zd+r6yuDA/lP0t/nyYXOAS/K0YL+dXuCop56SOOLm Vy9JNDmlMsY/WwIaKk8Ic+1dNWA+yu11iQJ+R8Ca+PttQHGKgjdwpbBLBNxqwXBH/u12 b/duTEDjGlAAqN+t5uxB7PEHRUSATNZDNBvtDcphz0/15/hOeO6T7p+d02k62kdahf3d kVHrVVTwi6ma6/zpd3AZTOcONJBnKru/IUqst8wdL7Xjj+Cxqer92y4HjCSsHN4Qd+L/ e/6HshR1NFhlRsyp0LSwKggA/AHpHC6q+xaZkmeyOYCwEw5PNz1q8hwwx6qGVD7mvlvD TqFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pgYvIUnC; 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 g11-v6si13525653pgs.179.2018.11.11.16.04.38; Sun, 11 Nov 2018 16:04:53 -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=pgYvIUnC; 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 S1732352AbeKLJym (ORCPT + 99 others); Mon, 12 Nov 2018 04:54:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:34412 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731952AbeKLIRs (ORCPT ); Mon, 12 Nov 2018 03:17:48 -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 3D7872175B; Sun, 11 Nov 2018 22:27:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975272; bh=GFB9fz2oQabVNNyaLVo5sv5BzFh/uMaHCbTL9OjGJpg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pgYvIUnC9+gPeVGnmwLk7OU3fHNkRGKxBwOfwlqLEPEeoDoaGAm32r+ngYMUMBPF8 qj1iZnoRRQ/jMEIYD0HqAP+txdxpY8ZZkE/C3ZP76abav5iYeE3GF2UNfH4i3G6k7X JZZq4XBHJaVmXSPgo5g5HewmbMLyJb+HopKyxibE= 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.19 141/361] scsi: megaraid_sas: fix a missing-check bug Date: Sun, 11 Nov 2018 14:18:08 -0800 Message-Id: <20181111221640.265943528@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@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.19-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 @@ -7523,6 +7523,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);