Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <aradford@gmail.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-scsi@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/20230105004757.never.017-kees@kernel.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Kees Cook and committed by
Martin K. Petersen
45b379f2 dae0bb3e

+8 -8
+6 -6
drivers/scsi/3w-sas.c
··· 690 690 newcommand->request_id__lunl = 691 691 cpu_to_le16(TW_REQ_LUN_IN(TW_LUN_OUT(newcommand->request_id__lunl), request_id)); 692 692 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)); 694 694 newcommand->sg_list[0].length = TW_CPU_TO_SGL(length); 695 695 } 696 696 newcommand->sgl_entries__lunh = ··· 702 702 if (TW_SGL_OUT(oldcommand->opcode__sgloffset)) { 703 703 /* Load the sg list */ 704 704 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)); 706 706 sgl->length = TW_CPU_TO_SGL(length); 707 707 oldcommand->size += pae; 708 708 oldcommand->size += sizeof(dma_addr_t) > 4 ? 1 : 0; ··· 748 748 data_buffer_length_adjusted = (driver_command.buffer_length + 511) & ~511; 749 749 750 750 /* 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); 752 752 if (!cpu_addr) { 753 753 retval = -ENOMEM; 754 754 goto out2; ··· 757 757 tw_ioctl = (TW_Ioctl_Buf_Apache *)cpu_addr; 758 758 759 759 /* 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))) 761 761 goto out3; 762 762 763 763 /* See which ioctl we are doing */ ··· 815 815 } 816 816 817 817 /* 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) 819 819 retval = 0; 820 820 out3: 821 821 /* 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); 823 823 out2: 824 824 mutex_unlock(&tw_dev->ioctl_lock); 825 825 out:
+2 -2
drivers/scsi/3w-sas.h
··· 335 335 TW_Ioctl_Driver_Command driver_command; 336 336 char padding[488]; 337 337 TW_Command_Full firmware_command; 338 - char data_buffer[1]; 338 + char data_buffer[]; 339 339 } TW_Ioctl_Buf_Apache; 340 340 341 341 /* GetParam descriptor */ ··· 344 344 unsigned short parameter_id; 345 345 unsigned short parameter_size_bytes; 346 346 unsigned short actual_parameter_size_bytes; 347 - unsigned char data[1]; 347 + unsigned char data[]; 348 348 } TW_Param_Apache; 349 349 350 350 /* Compatibility information structure */