* [PATCH] esas2r: Use flex array destination for memcpy()
@ 2022-09-01 20:57 Kees Cook
2022-09-01 22:12 ` Gustavo A. R. Silva
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Kees Cook @ 2022-09-01 20:57 UTC (permalink / raw)
To: Bradley Grove
Cc: Kees Cook, James E.J. Bottomley, Martin K. Petersen, linux-scsi,
linux-kernel, linux-hardening
In preparation for FORTIFY_SOURCE performing run-time destination buffer
bounds checking for memcpy(), specify the destination output buffer
explicitly, instead of asking memcpy() to write past the end of what
looked like a fixed-size object. Silences future run-time warning:
memcpy: detected field-spanning write (size 80) of single field "trc + 1" (size 64)
There is no binary code output differences from this change.
Cc: Bradley Grove <linuxdrivers@attotech.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
drivers/scsi/esas2r/atioctl.h | 1 +
drivers/scsi/esas2r/esas2r_ioctl.c | 3 +--
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/esas2r/atioctl.h b/drivers/scsi/esas2r/atioctl.h
index ff2ad9b38575..dd3437412ffc 100644
--- a/drivers/scsi/esas2r/atioctl.h
+++ b/drivers/scsi/esas2r/atioctl.h
@@ -831,6 +831,7 @@ struct __packed atto_hba_trace {
u32 total_length;
u32 trace_mask;
u8 reserved2[48];
+ u8 contents[];
};
#define ATTO_FUNC_SCSI_PASS_THRU 0x04
diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c b/drivers/scsi/esas2r/esas2r_ioctl.c
index 08f4e43c7d9e..e003d923acbf 100644
--- a/drivers/scsi/esas2r/esas2r_ioctl.c
+++ b/drivers/scsi/esas2r/esas2r_ioctl.c
@@ -947,10 +947,9 @@ static int hba_ioctl_callback(struct esas2r_adapter *a,
break;
}
- memcpy(trc + 1,
+ memcpy(trc->contents,
a->fw_coredump_buff + offset,
len);
-
hi->data_length = len;
} else if (trc->trace_func == ATTO_TRC_TF_RESET) {
memset(a->fw_coredump_buff, 0,
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] esas2r: Use flex array destination for memcpy()
2022-09-01 20:57 [PATCH] esas2r: Use flex array destination for memcpy() Kees Cook
@ 2022-09-01 22:12 ` Gustavo A. R. Silva
2022-09-03 8:47 ` Gustavo A. R. Silva
2022-09-07 2:25 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2022-09-01 22:12 UTC (permalink / raw)
To: Kees Cook, Bradley Grove
Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi,
linux-kernel, linux-hardening
On 9/1/22 15:57, Kees Cook wrote:
> In preparation for FORTIFY_SOURCE performing run-time destination buffer
> bounds checking for memcpy(), specify the destination output buffer
> explicitly, instead of asking memcpy() to write past the end of what
> looked like a fixed-size object. Silences future run-time warning:
>
> memcpy: detected field-spanning write (size 80) of single field "trc + 1" (size 64)
>
> There is no binary code output differences from this change.
>
> Cc: Bradley Grove <linuxdrivers@attotech.com>
> Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
> Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
> Cc: linux-scsi@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks
--
Gustavo
> ---
> drivers/scsi/esas2r/atioctl.h | 1 +
> drivers/scsi/esas2r/esas2r_ioctl.c | 3 +--
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/esas2r/atioctl.h b/drivers/scsi/esas2r/atioctl.h
> index ff2ad9b38575..dd3437412ffc 100644
> --- a/drivers/scsi/esas2r/atioctl.h
> +++ b/drivers/scsi/esas2r/atioctl.h
> @@ -831,6 +831,7 @@ struct __packed atto_hba_trace {
> u32 total_length;
> u32 trace_mask;
> u8 reserved2[48];
> + u8 contents[];
> };
>
> #define ATTO_FUNC_SCSI_PASS_THRU 0x04
> diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c b/drivers/scsi/esas2r/esas2r_ioctl.c
> index 08f4e43c7d9e..e003d923acbf 100644
> --- a/drivers/scsi/esas2r/esas2r_ioctl.c
> +++ b/drivers/scsi/esas2r/esas2r_ioctl.c
> @@ -947,10 +947,9 @@ static int hba_ioctl_callback(struct esas2r_adapter *a,
> break;
> }
>
> - memcpy(trc + 1,
> + memcpy(trc->contents,
> a->fw_coredump_buff + offset,
> len);
> -
> hi->data_length = len;
> } else if (trc->trace_func == ATTO_TRC_TF_RESET) {
> memset(a->fw_coredump_buff, 0,
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] esas2r: Use flex array destination for memcpy()
2022-09-01 20:57 [PATCH] esas2r: Use flex array destination for memcpy() Kees Cook
2022-09-01 22:12 ` Gustavo A. R. Silva
@ 2022-09-03 8:47 ` Gustavo A. R. Silva
2022-09-07 2:25 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2022-09-03 8:47 UTC (permalink / raw)
To: Kees Cook
Cc: Bradley Grove, James E.J. Bottomley, Martin K. Petersen,
linux-scsi, linux-kernel, linux-hardening
On Thu, Sep 01, 2022 at 01:57:29PM -0700, Kees Cook wrote:
> In preparation for FORTIFY_SOURCE performing run-time destination buffer
> bounds checking for memcpy(), specify the destination output buffer
> explicitly, instead of asking memcpy() to write past the end of what
> looked like a fixed-size object. Silences future run-time warning:
>
> memcpy: detected field-spanning write (size 80) of single field "trc + 1" (size 64)
>
> There is no binary code output differences from this change.
>
> Cc: Bradley Grove <linuxdrivers@attotech.com>
> Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
> Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
> Cc: linux-scsi@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks
--
Gustavo
> ---
> drivers/scsi/esas2r/atioctl.h | 1 +
> drivers/scsi/esas2r/esas2r_ioctl.c | 3 +--
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/esas2r/atioctl.h b/drivers/scsi/esas2r/atioctl.h
> index ff2ad9b38575..dd3437412ffc 100644
> --- a/drivers/scsi/esas2r/atioctl.h
> +++ b/drivers/scsi/esas2r/atioctl.h
> @@ -831,6 +831,7 @@ struct __packed atto_hba_trace {
> u32 total_length;
> u32 trace_mask;
> u8 reserved2[48];
> + u8 contents[];
> };
>
> #define ATTO_FUNC_SCSI_PASS_THRU 0x04
> diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c b/drivers/scsi/esas2r/esas2r_ioctl.c
> index 08f4e43c7d9e..e003d923acbf 100644
> --- a/drivers/scsi/esas2r/esas2r_ioctl.c
> +++ b/drivers/scsi/esas2r/esas2r_ioctl.c
> @@ -947,10 +947,9 @@ static int hba_ioctl_callback(struct esas2r_adapter *a,
> break;
> }
>
> - memcpy(trc + 1,
> + memcpy(trc->contents,
> a->fw_coredump_buff + offset,
> len);
> -
> hi->data_length = len;
> } else if (trc->trace_func == ATTO_TRC_TF_RESET) {
> memset(a->fw_coredump_buff, 0,
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] esas2r: Use flex array destination for memcpy()
2022-09-01 20:57 [PATCH] esas2r: Use flex array destination for memcpy() Kees Cook
2022-09-01 22:12 ` Gustavo A. R. Silva
2022-09-03 8:47 ` Gustavo A. R. Silva
@ 2022-09-07 2:25 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2022-09-07 2:25 UTC (permalink / raw)
To: Kees Cook
Cc: Bradley Grove, James E.J. Bottomley, Martin K. Petersen,
linux-scsi, linux-kernel, linux-hardening
Kees,
> In preparation for FORTIFY_SOURCE performing run-time destination
> buffer bounds checking for memcpy(), specify the destination output
> buffer explicitly, instead of asking memcpy() to write past the end of
> what looked like a fixed-size object. Silences future run-time
> warning:
>
> memcpy: detected field-spanning write (size 80) of single field "trc + 1" (size 64)
>
> There is no binary code output differences from this change.
Applied to 6.1/scsi-staging, thanks!
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-09-07 2:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-01 20:57 [PATCH] esas2r: Use flex array destination for memcpy() Kees Cook
2022-09-01 22:12 ` Gustavo A. R. Silva
2022-09-03 8:47 ` Gustavo A. R. Silva
2022-09-07 2:25 ` Martin K. Petersen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).