* [PATCH] scsi: libfcoe: Replace all non-returning strlcpy with strscpy
@ 2023-05-30 15:58 Azeem Shaikh
2023-05-30 23:17 ` Kees Cook
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Azeem Shaikh @ 2023-05-30 15:58 UTC (permalink / raw)
To: Hannes Reinecke
Cc: linux-hardening, Azeem Shaikh, linux-scsi, linux-kernel,
James E.J. Bottomley, Martin K. Petersen
strlcpy() reads the entire source buffer first.
This read may exceed the destination size limit.
This is both inefficient and can lead to linear read
overflows if a source string is not NUL-terminated [1].
In an effort to remove strlcpy() completely [2], replace
strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.
[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89
Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>
---
drivers/scsi/fcoe/fcoe_transport.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/fcoe/fcoe_transport.c b/drivers/scsi/fcoe/fcoe_transport.c
index 46b0bf237be1..a48d24af9ac3 100644
--- a/drivers/scsi/fcoe/fcoe_transport.c
+++ b/drivers/scsi/fcoe/fcoe_transport.c
@@ -711,7 +711,7 @@ static struct net_device *fcoe_if_to_netdev(const char *buffer)
char ifname[IFNAMSIZ + 2];
if (buffer) {
- strlcpy(ifname, buffer, IFNAMSIZ);
+ strscpy(ifname, buffer, IFNAMSIZ);
cp = ifname + strlen(ifname);
while (--cp >= ifname && *cp == '\n')
*cp = '\0';
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] scsi: libfcoe: Replace all non-returning strlcpy with strscpy
2023-05-30 15:58 [PATCH] scsi: libfcoe: Replace all non-returning strlcpy with strscpy Azeem Shaikh
@ 2023-05-30 23:17 ` Kees Cook
2023-05-31 22:02 ` Martin K. Petersen
2023-06-08 1:42 ` Martin K. Petersen
2 siblings, 0 replies; 5+ messages in thread
From: Kees Cook @ 2023-05-30 23:17 UTC (permalink / raw)
To: Azeem Shaikh
Cc: Hannes Reinecke, linux-hardening, linux-scsi, linux-kernel,
James E.J. Bottomley, Martin K. Petersen
On Tue, May 30, 2023 at 03:58:18PM +0000, Azeem Shaikh wrote:
> strlcpy() reads the entire source buffer first.
> This read may exceed the destination size limit.
> This is both inefficient and can lead to linear read
> overflows if a source string is not NUL-terminated [1].
> In an effort to remove strlcpy() completely [2], replace
> strlcpy() here with strscpy().
> No return values were used, so direct replacement is safe.
>
> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
> [2] https://github.com/KSPP/linux/issues/89
>
> Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] scsi: libfcoe: Replace all non-returning strlcpy with strscpy
2023-05-30 15:58 [PATCH] scsi: libfcoe: Replace all non-returning strlcpy with strscpy Azeem Shaikh
2023-05-30 23:17 ` Kees Cook
@ 2023-05-31 22:02 ` Martin K. Petersen
2023-05-31 22:40 ` Azeem Shaikh
2023-06-08 1:42 ` Martin K. Petersen
2 siblings, 1 reply; 5+ messages in thread
From: Martin K. Petersen @ 2023-05-31 22:02 UTC (permalink / raw)
To: Azeem Shaikh
Cc: Hannes Reinecke, linux-hardening, linux-scsi, linux-kernel,
James E.J. Bottomley, Martin K. Petersen
Azeem,
> strlcpy() reads the entire source buffer first. This read may exceed
> the destination size limit. This is both inefficient and can lead to
> linear read overflows if a source string is not NUL-terminated [1]. In
> an effort to remove strlcpy() completely [2], replace strlcpy() here
> with strscpy(). No return values were used, so direct replacement is
> safe.
Applied to 6.5/scsi-staging!
PS. It would help if you could submit changes like these as a series in
the future so I don't have to track each patch individually.
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] scsi: libfcoe: Replace all non-returning strlcpy with strscpy
2023-05-31 22:02 ` Martin K. Petersen
@ 2023-05-31 22:40 ` Azeem Shaikh
0 siblings, 0 replies; 5+ messages in thread
From: Azeem Shaikh @ 2023-05-31 22:40 UTC (permalink / raw)
To: Martin K. Petersen
Cc: Hannes Reinecke, linux-hardening, linux-scsi, linux-kernel,
James E.J. Bottomley
On Wed, May 31, 2023 at 6:03 PM Martin K. Petersen
<martin.petersen@oracle.com> wrote:
>
>
> Azeem,
>
> > strlcpy() reads the entire source buffer first. This read may exceed
> > the destination size limit. This is both inefficient and can lead to
> > linear read overflows if a source string is not NUL-terminated [1]. In
> > an effort to remove strlcpy() completely [2], replace strlcpy() here
> > with strscpy(). No return values were used, so direct replacement is
> > safe.
>
> Applied to 6.5/scsi-staging!
Thanks Martin!
>
> PS. It would help if you could submit changes like these as a series in
> the future so I don't have to track each patch individually.
>
Sure, I can do that.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] scsi: libfcoe: Replace all non-returning strlcpy with strscpy
2023-05-30 15:58 [PATCH] scsi: libfcoe: Replace all non-returning strlcpy with strscpy Azeem Shaikh
2023-05-30 23:17 ` Kees Cook
2023-05-31 22:02 ` Martin K. Petersen
@ 2023-06-08 1:42 ` Martin K. Petersen
2 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2023-06-08 1:42 UTC (permalink / raw)
To: Hannes Reinecke, Azeem Shaikh
Cc: Martin K . Petersen, linux-hardening, linux-scsi, linux-kernel,
James E.J. Bottomley
On Tue, 30 May 2023 15:58:18 +0000, Azeem Shaikh wrote:
> strlcpy() reads the entire source buffer first.
> This read may exceed the destination size limit.
> This is both inefficient and can lead to linear read
> overflows if a source string is not NUL-terminated [1].
> In an effort to remove strlcpy() completely [2], replace
> strlcpy() here with strscpy().
> No return values were used, so direct replacement is safe.
>
> [...]
Applied to 6.5/scsi-queue, thanks!
[1/1] scsi: libfcoe: Replace all non-returning strlcpy with strscpy
https://git.kernel.org/mkp/scsi/c/4dae0262fb99
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-06-08 1:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-30 15:58 [PATCH] scsi: libfcoe: Replace all non-returning strlcpy with strscpy Azeem Shaikh
2023-05-30 23:17 ` Kees Cook
2023-05-31 22:02 ` Martin K. Petersen
2023-05-31 22:40 ` Azeem Shaikh
2023-06-08 1:42 ` 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