Skip to content

Commit 45b379f

Browse files
keesmartinkpetersen
authored andcommitted
scsi: 3w-sas: Replace 1-element arrays with flexible array members
One-element arrays (and multi-element arrays being treated as dynamically sized) are deprecated[1] and are being replaced with flexible array members in support of the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy(), correctly instrument array indexing with UBSAN_BOUNDS, and to globally enable -fstrict-flex-arrays=3. Replace one-element arrays with flexible-array member in TW_Ioctl_Buf_Apache and TW_Param_Apache, adjusting the explicit sizing calculations at the same time. This results in no differences in binary output. [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays Cc: Adam Radford <[email protected]> Cc: "James E.J. Bottomley" <[email protected]> Cc: "Martin K. Petersen" <[email protected]> Cc: "Gustavo A. R. Silva" <[email protected]> Cc: [email protected] Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Gustavo A. R. Silva <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent dae0bb3 commit 45b379f

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

drivers/scsi/3w-sas.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ static void twl_load_sgl(TW_Device_Extension *tw_dev, TW_Command_Full *full_comm
690690
newcommand->request_id__lunl =
691691
cpu_to_le16(TW_REQ_LUN_IN(TW_LUN_OUT(newcommand->request_id__lunl), request_id));
692692
if (length) {
693-
newcommand->sg_list[0].address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache) - 1);
693+
newcommand->sg_list[0].address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache));
694694
newcommand->sg_list[0].length = TW_CPU_TO_SGL(length);
695695
}
696696
newcommand->sgl_entries__lunh =
@@ -702,7 +702,7 @@ static void twl_load_sgl(TW_Device_Extension *tw_dev, TW_Command_Full *full_comm
702702
if (TW_SGL_OUT(oldcommand->opcode__sgloffset)) {
703703
/* Load the sg list */
704704
sgl = (TW_SG_Entry_ISO *)((u32 *)oldcommand+oldcommand->size - (sizeof(TW_SG_Entry_ISO)/4) + pae + (sizeof(dma_addr_t) > 4 ? 1 : 0));
705-
sgl->address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache) - 1);
705+
sgl->address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache));
706706
sgl->length = TW_CPU_TO_SGL(length);
707707
oldcommand->size += pae;
708708
oldcommand->size += sizeof(dma_addr_t) > 4 ? 1 : 0;
@@ -748,7 +748,7 @@ static long twl_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long
748748
data_buffer_length_adjusted = (driver_command.buffer_length + 511) & ~511;
749749

750750
/* Now allocate ioctl buf memory */
751-
cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_Ioctl_Buf_Apache) - 1, &dma_handle, GFP_KERNEL);
751+
cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted + sizeof(TW_Ioctl_Buf_Apache), &dma_handle, GFP_KERNEL);
752752
if (!cpu_addr) {
753753
retval = -ENOMEM;
754754
goto out2;
@@ -757,7 +757,7 @@ static long twl_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long
757757
tw_ioctl = (TW_Ioctl_Buf_Apache *)cpu_addr;
758758

759759
/* Now copy down the entire ioctl */
760-
if (copy_from_user(tw_ioctl, argp, driver_command.buffer_length + sizeof(TW_Ioctl_Buf_Apache) - 1))
760+
if (copy_from_user(tw_ioctl, argp, driver_command.buffer_length + sizeof(TW_Ioctl_Buf_Apache)))
761761
goto out3;
762762

763763
/* See which ioctl we are doing */
@@ -815,11 +815,11 @@ static long twl_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long
815815
}
816816

817817
/* Now copy the entire response to userspace */
818-
if (copy_to_user(argp, tw_ioctl, sizeof(TW_Ioctl_Buf_Apache) + driver_command.buffer_length - 1) == 0)
818+
if (copy_to_user(argp, tw_ioctl, sizeof(TW_Ioctl_Buf_Apache) + driver_command.buffer_length) == 0)
819819
retval = 0;
820820
out3:
821821
/* Now free ioctl buf memory */
822-
dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_Ioctl_Buf_Apache) - 1, cpu_addr, dma_handle);
822+
dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted + sizeof(TW_Ioctl_Buf_Apache), cpu_addr, dma_handle);
823823
out2:
824824
mutex_unlock(&tw_dev->ioctl_lock);
825825
out:

drivers/scsi/3w-sas.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ typedef struct TAG_TW_Ioctl_Apache {
335335
TW_Ioctl_Driver_Command driver_command;
336336
char padding[488];
337337
TW_Command_Full firmware_command;
338-
char data_buffer[1];
338+
char data_buffer[];
339339
} TW_Ioctl_Buf_Apache;
340340

341341
/* GetParam descriptor */
@@ -344,7 +344,7 @@ typedef struct {
344344
unsigned short parameter_id;
345345
unsigned short parameter_size_bytes;
346346
unsigned short actual_parameter_size_bytes;
347-
unsigned char data[1];
347+
unsigned char data[];
348348
} TW_Param_Apache;
349349

350350
/* Compatibility information structure */

0 commit comments

Comments
 (0)