Skip to content

Commit 381d34e

Browse files
arndbmartinkpetersen
authored andcommitted
scsi: megaraid_sas: Check user-provided offsets
It sounds unwise to let user space pass an unchecked 32-bit offset into a kernel structure in an ioctl. This is an unsigned variable, so checking the upper bound for the size of the structure it points into is sufficient to avoid data corruption, but as the pointer might also be unaligned, it has to be written carefully as well. While I stumbled over this problem by reading the code, I did not continue checking the function for further problems like it. Link: https://lore.kernel.org/r/20201030164450.1253641-2-arnd@kernel.org Fixes: c4a3e0a ("[SCSI] MegaRAID SAS RAID: new driver") Cc: <stable@vger.kernel.org> # v2.6.15+ Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 0770542 commit 381d34e

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

‎drivers/scsi/megaraid/megaraid_sas_base.c‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8134,7 +8134,7 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
81348134
int error = 0, i;
81358135
void *sense = NULL;
81368136
dma_addr_t sense_handle;
8137-
unsigned long *sense_ptr;
8137+
void *sense_ptr;
81388138
u32 opcode = 0;
81398139
int ret = DCMD_SUCCESS;
81408140

@@ -8257,19 +8257,25 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
82578257
}
82588258

82598259
if (ioc->sense_len) {
8260+
/* make sure the pointer is part of the frame */
8261+
if (ioc->sense_off >
8262+
(sizeof(union megasas_frame) - sizeof(__le64))) {
8263+
error = -EINVAL;
8264+
goto out;
8265+
}
8266+
82608267
sense = dma_alloc_coherent(&instance->pdev->dev, ioc->sense_len,
82618268
&sense_handle, GFP_KERNEL);
82628269
if (!sense) {
82638270
error = -ENOMEM;
82648271
goto out;
82658272
}
82668273

8267-
sense_ptr =
8268-
(unsigned long *) ((unsigned long)cmd->frame + ioc->sense_off);
8274+
sense_ptr = (void *)cmd->frame + ioc->sense_off;
82698275
if (instance->consistent_mask_64bit)
8270-
*sense_ptr = cpu_to_le64(sense_handle);
8276+
put_unaligned_le64(sense_handle, sense_ptr);
82718277
else
8272-
*sense_ptr = cpu_to_le32(sense_handle);
8278+
put_unaligned_le32(sense_handle, sense_ptr);
82738279
}
82748280

82758281
/*

0 commit comments

Comments
 (0)