From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Martin K. Petersen" Subject: Re: [PATCH] scsi: megaraid_sas: fix a missing-check bug Date: Mon, 15 Oct 2018 23:43:12 -0400 Message-ID: References: <1538850861-26882-1-git-send-email-wang6495@umn.edu> Mime-Version: 1.0 Content-Type: text/plain Return-path: In-Reply-To: <1538850861-26882-1-git-send-email-wang6495@umn.edu> (Wenwen Wang's message of "Sat, 6 Oct 2018 13:34:21 -0500") Sender: linux-kernel-owner@vger.kernel.org To: Wenwen Wang Cc: Kangjie Lu , Kashyap Desai , Sumit Saxena , Shivasharan S , "James E.J. Bottomley" , "Martin K. Petersen" , "open list:MEGARAID SCSI/SAS DRIVERS" , "open list:MEGARAID SCSI/SAS DRIVERS" , open list List-Id: linux-scsi@vger.kernel.org Wenwen, > 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. Broadcom folks: Please review! -- Martin K. Petersen Oracle Linux Engineering