]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-6.6/scsi-mpi3mr-avoid-memcpy-field-spanning-write-warnin.patch
Fixes for 6.6
[thirdparty/kernel/stable-queue.git] / queue-6.6 / scsi-mpi3mr-avoid-memcpy-field-spanning-write-warnin.patch
1 From 4b6c22f4f1d4a405547e60d9734acb60add17f6c Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Sat, 23 Mar 2024 17:41:55 +0900
4 Subject: scsi: mpi3mr: Avoid memcpy field-spanning write WARNING
5
6 From: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
7
8 [ Upstream commit 429846b4b6ce9853e0d803a2357bb2e55083adf0 ]
9
10 When the "storcli2 show" command is executed for eHBA-9600, mpi3mr driver
11 prints this WARNING message:
12
13 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)
14 WARNING: CPU: 0 PID: 12760 at drivers/scsi/mpi3mr/mpi3mr_app.c:1658 mpi3mr_bsg_request+0x6b12/0x7f10 [mpi3mr]
15
16 The cause of the WARN is 128 bytes memcpy to the 1 byte size array "__u8
17 replay_buf[1]" in the struct mpi3mr_bsg_in_reply_buf. The array is intended
18 to be a flexible length array, so the WARN is a false positive.
19
20 To suppress the WARN, remove the constant number '1' from the array
21 declaration and clarify that it has flexible length. Also, adjust the
22 memory allocation size to match the change.
23
24 Suggested-by: Sathya Prakash Veerichetty <sathya.prakash@broadcom.com>
25 Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
26 Link: https://lore.kernel.org/r/20240323084155.166835-1-shinichiro.kawasaki@wdc.com
27 Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
28 Signed-off-by: Sasha Levin <sashal@kernel.org>
29 ---
30 drivers/scsi/mpi3mr/mpi3mr_app.c | 2 +-
31 include/uapi/scsi/scsi_bsg_mpi3mr.h | 2 +-
32 2 files changed, 2 insertions(+), 2 deletions(-)
33
34 diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c b/drivers/scsi/mpi3mr/mpi3mr_app.c
35 index 9dacbb8570c93..aa5b535e6662b 100644
36 --- a/drivers/scsi/mpi3mr/mpi3mr_app.c
37 +++ b/drivers/scsi/mpi3mr/mpi3mr_app.c
38 @@ -1345,7 +1345,7 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job, unsigned int *reply
39 if ((mpirep_offset != 0xFF) &&
40 drv_bufs[mpirep_offset].bsg_buf_len) {
41 drv_buf_iter = &drv_bufs[mpirep_offset];
42 - drv_buf_iter->kern_buf_len = (sizeof(*bsg_reply_buf) - 1 +
43 + drv_buf_iter->kern_buf_len = (sizeof(*bsg_reply_buf) +
44 mrioc->reply_sz);
45 bsg_reply_buf = kzalloc(drv_buf_iter->kern_buf_len, GFP_KERNEL);
46
47 diff --git a/include/uapi/scsi/scsi_bsg_mpi3mr.h b/include/uapi/scsi/scsi_bsg_mpi3mr.h
48 index 907d345f04f93..353183e863e47 100644
49 --- a/include/uapi/scsi/scsi_bsg_mpi3mr.h
50 +++ b/include/uapi/scsi/scsi_bsg_mpi3mr.h
51 @@ -382,7 +382,7 @@ struct mpi3mr_bsg_in_reply_buf {
52 __u8 mpi_reply_type;
53 __u8 rsvd1;
54 __u16 rsvd2;
55 - __u8 reply_buf[1];
56 + __u8 reply_buf[];
57 };
58
59 /**
60 --
61 2.43.0
62