diff mbox series

[v2] scsi: mpi3mr: Avoid memcpy field-spanning write WARNING

Message ID 20240323084155.166835-1-shinichiro.kawasaki@wdc.com
State New
Headers show
Series [v2] scsi: mpi3mr: Avoid memcpy field-spanning write WARNING | expand

Commit Message

Shinichiro Kawasaki March 23, 2024, 8:41 a.m. UTC
When the "storcli2 show" command is executed for eHBA-9600, mpi3mr
driver prints this WARNING message:

  memcpy: detected field-spanning write (size 128) of single field "bsg_reply_buf->reply_buf" at drivers/scsi/mpi3mr/mpi3mr_app.c:1658 (size 1)
  WARNING: CPU: 0 PID: 12760 at drivers/scsi/mpi3mr/mpi3mr_app.c:1658 mpi3mr_bsg_request+0x6b12/0x7f10 [mpi3mr]

The cause of the WARN is 128 bytes memcpy to the 1 byte size array
"__u8 replay_buf[1]" in the struct mpi3mr_bsg_in_reply_buf. The array is
intended to be a flexible length array, then the WARN is a false
positive. To suppress the WARN, remove the constant number '1' from the
array declaration and clarify that it has flexible length. Also, adjust
the memory allocation size to match the change.

Suggested-by: Sathya Prakash Veerichetty <sathya.prakash@broadcom.com>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
Changes from v1:
* Modify the array declaration for flexible length instead of two memcpy calls

 drivers/scsi/mpi3mr/mpi3mr_app.c    | 2 +-
 include/uapi/scsi/scsi_bsg_mpi3mr.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Martin K. Petersen March 26, 2024, 1:21 a.m. UTC | #1
On Sat, 23 Mar 2024 17:41:55 +0900, Shin'ichiro Kawasaki wrote:

> When the "storcli2 show" command is executed for eHBA-9600, mpi3mr
> driver prints this WARNING message:
> 
>   memcpy: detected field-spanning write (size 128) of single field "bsg_reply_buf->reply_buf" at drivers/scsi/mpi3mr/mpi3mr_app.c:1658 (size 1)
>   WARNING: CPU: 0 PID: 12760 at drivers/scsi/mpi3mr/mpi3mr_app.c:1658 mpi3mr_bsg_request+0x6b12/0x7f10 [mpi3mr]
> 
> The cause of the WARN is 128 bytes memcpy to the 1 byte size array
> "__u8 replay_buf[1]" in the struct mpi3mr_bsg_in_reply_buf. The array is
> intended to be a flexible length array, then the WARN is a false
> positive. To suppress the WARN, remove the constant number '1' from the
> array declaration and clarify that it has flexible length. Also, adjust
> the memory allocation size to match the change.
> 
> [...]

Applied to 6.9/scsi-fixes, thanks!

[1/1] scsi: mpi3mr: Avoid memcpy field-spanning write WARNING
      https://git.kernel.org/mkp/scsi/c/429846b4b6ce
diff mbox series

Patch

diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c b/drivers/scsi/mpi3mr/mpi3mr_app.c
index 0380996b5ad2..55d590b91947 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_app.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_app.c
@@ -1644,7 +1644,7 @@  static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
 	if ((mpirep_offset != 0xFF) &&
 	    drv_bufs[mpirep_offset].bsg_buf_len) {
 		drv_buf_iter = &drv_bufs[mpirep_offset];
-		drv_buf_iter->kern_buf_len = (sizeof(*bsg_reply_buf) - 1 +
+		drv_buf_iter->kern_buf_len = (sizeof(*bsg_reply_buf) +
 					   mrioc->reply_sz);
 		bsg_reply_buf = kzalloc(drv_buf_iter->kern_buf_len, GFP_KERNEL);
 
diff --git a/include/uapi/scsi/scsi_bsg_mpi3mr.h b/include/uapi/scsi/scsi_bsg_mpi3mr.h
index c72ce387286a..30a5c1a59376 100644
--- a/include/uapi/scsi/scsi_bsg_mpi3mr.h
+++ b/include/uapi/scsi/scsi_bsg_mpi3mr.h
@@ -382,7 +382,7 @@  struct mpi3mr_bsg_in_reply_buf {
 	__u8	mpi_reply_type;
 	__u8	rsvd1;
 	__u16	rsvd2;
-	__u8	reply_buf[1];
+	__u8	reply_buf[];
 };
 
 /**