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: mvumi: 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 struct
mvumi_msg_frame, struct mvumi_rsp_frame, and struct mvumi_hs_header,
adjusting the explicit sizing calculations at the same time.

This results in no functional differences in binary output. An explicit add
is now folded into the size calculation:

│ mov 0x1070(%r14),%eax
│ - add $0x4,%eax
│ - movabs $0xfffffffdc,%rbx
│ + movabs $0xfffffffe0,%rbx
│ add %rax,%rbx

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

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/20230105011143.never.569-kees@kernel.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Kees Cook and committed by
Martin K. Petersen
201e0a7c 45b379f2

+5 -5
+2 -2
drivers/scsi/mvumi.c
··· 1841 1841 cmd->frame->request_id = mhba->io_seq++; 1842 1842 cmd->request_id = cmd->frame->request_id; 1843 1843 mhba->tag_cmd[cmd->frame->tag] = cmd; 1844 - frame_len = sizeof(*ib_frame) - 4 + 1844 + frame_len = sizeof(*ib_frame) + 1845 1845 ib_frame->sg_counts * sizeof(struct mvumi_sgl); 1846 1846 if (mhba->hba_capability & HS_CAPABILITY_SUPPORT_DYN_SRC) { 1847 1847 struct mvumi_dyn_list_entry *dle; ··· 2387 2387 struct Scsi_Host *host = mhba->shost; 2388 2388 struct scsi_device *sdev = NULL; 2389 2389 int ret; 2390 - unsigned int max_sg = (mhba->ib_max_size + 4 - 2390 + unsigned int max_sg = (mhba->ib_max_size - 2391 2391 sizeof(struct mvumi_msg_frame)) / sizeof(struct mvumi_sgl); 2392 2392 2393 2393 host->irq = mhba->pdev->irq;
+3 -3
drivers/scsi/mvumi.h
··· 279 279 u16 request_id; 280 280 u16 reserved1; 281 281 u8 cdb[MAX_COMMAND_SIZE]; 282 - u32 payload[1]; 282 + u32 payload[]; 283 283 }; 284 284 285 285 /* ··· 294 294 u8 req_status; 295 295 u8 rsp_flag; /* Indicates the type of Data_Payload.*/ 296 296 u16 request_id; 297 - u32 payload[1]; 297 + u32 payload[]; 298 298 }; 299 299 300 300 struct mvumi_ob_data { ··· 380 380 u8 page_code; 381 381 u8 checksum; 382 382 u16 frame_length; 383 - u32 frame_content[1]; 383 + u32 frame_content[]; 384 384 }; 385 385 386 386 /*