[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <855e73f8-9b84-25b9-01e3-8ce368165b25@embeddedor.com>
Date: Wed, 10 Mar 2021 18:06:52 -0600
From: "Gustavo A. R. Silva" <gustavo@...eddedor.com>
To: Kees Cook <keescook@...omium.org>,
"Gustavo A. R. Silva" <gustavoars@...nel.org>
Cc: James Bottomley <jejb@...ux.ibm.com>,
Sathya Prakash <sathya.prakash@...adcom.com>,
Sreekanth Reddy <sreekanth.reddy@...adcom.com>,
Suganath Prabu Subramani
<suganath-prabu.subramani@...adcom.com>,
"Martin K. Petersen" <martin.petersen@...cle.com>,
MPT-FusionLinux.pdl@...adcom.com, linux-scsi@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-hardening@...r.kernel.org
Subject: Re: [PATCH v2][next] scsi: mpt3sas: Replace one-element array with
flexible-array in struct _MPI2_CONFIG_PAGE_IO_UNIT_3
On 3/10/21 13:07, Kees Cook wrote:
>> diff --git a/drivers/scsi/mpt3sas/mpi/mpi2_cnfg.h b/drivers/scsi/mpt3sas/mpi/mpi2_cnfg.h
>> index 43a3bf8ff428..d00431f553e1 100644
>> --- a/drivers/scsi/mpt3sas/mpi/mpi2_cnfg.h
>> +++ b/drivers/scsi/mpt3sas/mpi/mpi2_cnfg.h
>> @@ -992,7 +992,7 @@ typedef struct _MPI2_CONFIG_PAGE_IO_UNIT_1 {
>> *one and check the value returned for GPIOCount at runtime.
>> */
>> #ifndef MPI2_IO_UNIT_PAGE_3_GPIO_VAL_MAX
>> -#define MPI2_IO_UNIT_PAGE_3_GPIO_VAL_MAX (1)
>> +#define MPI2_IO_UNIT_PAGE_3_GPIO_VAL_MAX (36)
>> #endif
>>
>> typedef struct _MPI2_CONFIG_PAGE_IO_UNIT_3 {
>> diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
>> index 44f9a05db94e..23fcf29bfd67 100644
>> --- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
>> +++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
>> @@ -3203,7 +3203,7 @@ BRM_status_show(struct device *cdev, struct device_attribute *attr,
>> {
>> struct Scsi_Host *shost = class_to_shost(cdev);
>> struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
>> - Mpi2IOUnitPage3_t *io_unit_pg3 = NULL;
>> + Mpi2IOUnitPage3_t io_unit_pg3;
>> Mpi2ConfigReply_t mpi_reply;
>> u16 backup_rail_monitor_status = 0;
>> u16 ioc_status;
>> @@ -3221,16 +3221,10 @@ BRM_status_show(struct device *cdev, struct device_attribute *attr,
>> goto out;
>>
>> /* allocate upto GPIOVal 36 entries */
>> - sz = offsetof(Mpi2IOUnitPage3_t, GPIOVal) + (sizeof(u16) * 36);
>> - io_unit_pg3 = kzalloc(sz, GFP_KERNEL);
>> - if (!io_unit_pg3) {
>> - rc = -ENOMEM;
>> - ioc_err(ioc, "%s: failed allocating memory for iounit_pg3: (%d) bytes\n",
>> - __func__, sz);
>> - goto out;
>> - }
>> + sz = sizeof(io_unit_pg3);
>> + memset(&io_unit_pg3, 0, sz);
>
> I like this a lot. It makes the code way simpler.
>
> Putting this on the stack makes it faster, and it's less than 100 bytes,
> which seems entirely reasonable.
>
>>
>> - if (mpt3sas_config_get_iounit_pg3(ioc, &mpi_reply, io_unit_pg3, sz) !=
>> + if (mpt3sas_config_get_iounit_pg3(ioc, &mpi_reply, &io_unit_pg3, sz) !=
>
> The only thing I can imagine is if this ends up doing DMA, which isn't
> allowed on the stack. However, in looking down through the call path,
> it's _copied_ into DMA memory, so this appears entirely safe.
>
> Can you send this as a "normal" patch? Feel free to include:
>
> Reviewed-by: Kees Cook <keescook@...omium.org>
Done: https://lore.kernel.org/lkml/20210310235951.GA108661@embeddedor/
Thanks for the comments!
--
Gustavo
Powered by blists - more mailing lists