* [PATCH] scsi: megaraid_sas: Add flexible array member for SGLs
@ 2023-01-06 5:32 Kees Cook
2023-01-06 11:49 ` Holger Kiehl
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Kees Cook @ 2023-01-06 5:32 UTC (permalink / raw)
To: Kashyap Desai
Cc: Kees Cook, Holger Kiehl, Sumit Saxena, Shivasharan S,
James E.J. Bottomley, Martin K. Petersen, megaraidlinux.pdl,
linux-scsi, linux-kernel, linux-hardening
struct MPI2_RAID_SCSI_IO_REQUEST ends with a single SGL, but expects to
copy multiple. Add a flexible array member so the compiler can reason
about the size of the memcpy(). This will avoid the run-time false
positive warning:
memcpy: detected field-spanning write (size 128) of single field "&r1_cmd->io_request->SGL" at drivers/scsi/megaraid/megaraid_sas_fusion.c:3326 (size 16)
This change results in no binary output differences.
Reported-by: Holger Kiehl <Holger.Kiehl@dwd.de>
Link: https://lore.kernel.org/all/88de8faa-56c4-693d-2d3-67152ee72057@diagnostix.dwd.de/
Cc: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: Sumit Saxena <sumit.saxena@broadcom.com>
Cc: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: megaraidlinux.pdl@broadcom.com
Cc: linux-scsi@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
Holger, are you able to test this change? I expect it should do the
trick, but I don't have the hardware.
---
drivers/scsi/megaraid/megaraid_sas_fusion.c | 2 +-
drivers/scsi/megaraid/megaraid_sas_fusion.h | 5 ++++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index fe70f8f11435..6597e118c805 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -3323,7 +3323,7 @@ static void megasas_prepare_secondRaid1_IO(struct megasas_instance *instance,
/* copy the io request frame as well as 8 SGEs data for r1 command*/
memcpy(r1_cmd->io_request, cmd->io_request,
(sizeof(struct MPI2_RAID_SCSI_IO_REQUEST)));
- memcpy(&r1_cmd->io_request->SGL, &cmd->io_request->SGL,
+ memcpy(r1_cmd->io_request->SGLs, cmd->io_request->SGLs,
(fusion->max_sge_in_main_msg * sizeof(union MPI2_SGE_IO_UNION)));
/*sense buffer is different for r1 command*/
r1_cmd->io_request->SenseBufferLowAddress =
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h
index 49e9a9048ee7..b677d80e5874 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.h
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h
@@ -526,7 +526,10 @@ struct MPI2_RAID_SCSI_IO_REQUEST {
__le32 Control; /* 0x3C */
union MPI2_SCSI_IO_CDB_UNION CDB; /* 0x40 */
union RAID_CONTEXT_UNION RaidContext; /* 0x60 */
- union MPI2_SGE_IO_UNION SGL; /* 0x80 */
+ union {
+ union MPI2_SGE_IO_UNION SGL; /* 0x80 */
+ DECLARE_FLEX_ARRAY(union MPI2_SGE_IO_UNION, SGLs);
+ };
};
/*
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: megaraid_sas: Add flexible array member for SGLs
2023-01-06 5:32 [PATCH] scsi: megaraid_sas: Add flexible array member for SGLs Kees Cook
@ 2023-01-06 11:49 ` Holger Kiehl
2023-01-18 23:23 ` Martin K. Petersen
2023-01-27 3:22 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Holger Kiehl @ 2023-01-06 11:49 UTC (permalink / raw)
To: Kees Cook
Cc: Kashyap Desai, Sumit Saxena, Shivasharan S, James E.J. Bottomley,
Martin K. Petersen, megaraidlinux.pdl, linux-scsi, linux-kernel,
linux-hardening
On Thu, 5 Jan 2023, Kees Cook wrote:
> struct MPI2_RAID_SCSI_IO_REQUEST ends with a single SGL, but expects to
> copy multiple. Add a flexible array member so the compiler can reason
> about the size of the memcpy(). This will avoid the run-time false
> positive warning:
>
> memcpy: detected field-spanning write (size 128) of single field "&r1_cmd->io_request->SGL" at drivers/scsi/megaraid/megaraid_sas_fusion.c:3326 (size 16)
>
> This change results in no binary output differences.
>
> Reported-by: Holger Kiehl <Holger.Kiehl@dwd.de>
> Link: https://lore.kernel.org/all/88de8faa-56c4-693d-2d3-67152ee72057@diagnostix.dwd.de/
> Cc: Kashyap Desai <kashyap.desai@broadcom.com>
> Cc: Sumit Saxena <sumit.saxena@broadcom.com>
> Cc: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
> Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
> Cc: megaraidlinux.pdl@broadcom.com
> Cc: linux-scsi@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> Holger, are you able to test this change? I expect it should do the
> trick, but I don't have the hardware.
>
Yes, that does work. I no longer see 'memcpy: detected field-spanning
write (size 128)'. Tested this on 6.1.4-rc1. Did not see any other
regression.
Regards,
Holger
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: megaraid_sas: Add flexible array member for SGLs
2023-01-06 5:32 [PATCH] scsi: megaraid_sas: Add flexible array member for SGLs Kees Cook
2023-01-06 11:49 ` Holger Kiehl
@ 2023-01-18 23:23 ` Martin K. Petersen
2023-01-27 3:22 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2023-01-18 23:23 UTC (permalink / raw)
To: Kees Cook
Cc: Kashyap Desai, Holger Kiehl, Sumit Saxena, Shivasharan S,
James E.J. Bottomley, Martin K. Petersen, megaraidlinux.pdl,
linux-scsi, linux-kernel, linux-hardening
Kees,
> struct MPI2_RAID_SCSI_IO_REQUEST ends with a single SGL, but expects
> to copy multiple. Add a flexible array member so the compiler can
> reason about the size of the memcpy(). This will avoid the run-time
> false positive warning:
Applied to 6.3/scsi-staging, thanks!
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: megaraid_sas: Add flexible array member for SGLs
2023-01-06 5:32 [PATCH] scsi: megaraid_sas: Add flexible array member for SGLs Kees Cook
2023-01-06 11:49 ` Holger Kiehl
2023-01-18 23:23 ` Martin K. Petersen
@ 2023-01-27 3:22 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2023-01-27 3:22 UTC (permalink / raw)
To: Kashyap Desai, Kees Cook
Cc: Martin K . Petersen, Holger Kiehl, Sumit Saxena, Shivasharan S,
James E.J. Bottomley, megaraidlinux.pdl, linux-scsi,
linux-kernel, linux-hardening
On Thu, 05 Jan 2023 21:32:00 -0800, Kees Cook wrote:
> struct MPI2_RAID_SCSI_IO_REQUEST ends with a single SGL, but expects to
> copy multiple. Add a flexible array member so the compiler can reason
> about the size of the memcpy(). This will avoid the run-time false
> positive warning:
>
> memcpy: detected field-spanning write (size 128) of single field "&r1_cmd->io_request->SGL" at drivers/scsi/megaraid/megaraid_sas_fusion.c:3326 (size 16)
>
> [...]
Applied to 6.3/scsi-queue, thanks!
[1/1] scsi: megaraid_sas: Add flexible array member for SGLs
https://git.kernel.org/mkp/scsi/c/a9a3629592ab
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-01-27 3:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-06 5:32 [PATCH] scsi: megaraid_sas: Add flexible array member for SGLs Kees Cook
2023-01-06 11:49 ` Holger Kiehl
2023-01-18 23:23 ` Martin K. Petersen
2023-01-27 3:22 ` Martin K. Petersen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.