* [PATCH RESEND] scsi: scsi_ioctl: use strnlen in scsi_ioctl_get_pci
@ 2026-05-17 17:15 Thorsten Blum
2026-05-18 7:29 ` John Garry
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Thorsten Blum @ 2026-05-17 17:15 UTC (permalink / raw)
To: James E.J. Bottomley, Martin K. Petersen
Cc: Thorsten Blum, linux-scsi, linux-kernel
Use strnlen() to limit string scanning to 20 characters.
Reformat the code and use tabs instead of spaces while at it.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
drivers/scsi/scsi_ioctl.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
index 0ddc95bafc71..d98c2f19b1e9 100644
--- a/drivers/scsi/scsi_ioctl.c
+++ b/drivers/scsi/scsi_ioctl.c
@@ -176,10 +176,11 @@ static int scsi_ioctl_get_pci(struct scsi_device *sdev, void __user *arg)
name = dev_name(dev);
- /* compatibility with old ioctl which only returned
- * 20 characters */
- return copy_to_user(arg, name, min(strlen(name), (size_t)20))
- ? -EFAULT: 0;
+ /* compatibility with old ioctl which only returned 20 characters */
+ if (copy_to_user(arg, name, strnlen(name, 20)))
+ return -EFAULT;
+
+ return 0;
}
static int sg_get_version(int __user *p)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH RESEND] scsi: scsi_ioctl: use strnlen in scsi_ioctl_get_pci
2026-05-17 17:15 [PATCH RESEND] scsi: scsi_ioctl: use strnlen in scsi_ioctl_get_pci Thorsten Blum
@ 2026-05-18 7:29 ` John Garry
2026-05-23 1:13 ` Martin K. Petersen
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: John Garry @ 2026-05-18 7:29 UTC (permalink / raw)
To: Thorsten Blum, James E.J. Bottomley, Martin K. Petersen
Cc: linux-scsi, linux-kernel
On 17/05/2026 18:15, Thorsten Blum wrote:
> Use strnlen() to limit string scanning to 20 characters.
>
> Reformat the code and use tabs instead of spaces while at it.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: John Garry <john.g.garry@oracle.com>
> ---
> drivers/scsi/scsi_ioctl.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
> index 0ddc95bafc71..d98c2f19b1e9 100644
> --- a/drivers/scsi/scsi_ioctl.c
> +++ b/drivers/scsi/scsi_ioctl.c
> @@ -176,10 +176,11 @@ static int scsi_ioctl_get_pci(struct scsi_device *sdev, void __user *arg)
>
> name = dev_name(dev);
>
> - /* compatibility with old ioctl which only returned
> - * 20 characters */
> - return copy_to_user(arg, name, min(strlen(name), (size_t)20))
> - ? -EFAULT: 0;
> + /* compatibility with old ioctl which only returned 20 characters */
> + if (copy_to_user(arg, name, strnlen(name, 20)))
> + return -EFAULT;
> +
> + return 0;
> }
>
> static int sg_get_version(int __user *p)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RESEND] scsi: scsi_ioctl: use strnlen in scsi_ioctl_get_pci
2026-05-17 17:15 [PATCH RESEND] scsi: scsi_ioctl: use strnlen in scsi_ioctl_get_pci Thorsten Blum
2026-05-18 7:29 ` John Garry
@ 2026-05-23 1:13 ` Martin K. Petersen
2026-06-02 2:10 ` Martin K. Petersen
2026-06-02 9:19 ` David Laight
3 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2026-05-23 1:13 UTC (permalink / raw)
To: Thorsten Blum
Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi,
linux-kernel
Thorsten,
> Use strnlen() to limit string scanning to 20 characters.
>
> Reformat the code and use tabs instead of spaces while at it.
Applied to 7.2/scsi-staging, thanks!
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RESEND] scsi: scsi_ioctl: use strnlen in scsi_ioctl_get_pci
2026-05-17 17:15 [PATCH RESEND] scsi: scsi_ioctl: use strnlen in scsi_ioctl_get_pci Thorsten Blum
2026-05-18 7:29 ` John Garry
2026-05-23 1:13 ` Martin K. Petersen
@ 2026-06-02 2:10 ` Martin K. Petersen
2026-06-02 9:19 ` David Laight
3 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2026-06-02 2:10 UTC (permalink / raw)
To: James E.J. Bottomley, Thorsten Blum
Cc: Martin K . Petersen, linux-scsi, linux-kernel
On Sun, 17 May 2026 19:15:47 +0200, Thorsten Blum wrote:
> Use strnlen() to limit string scanning to 20 characters.
>
> Reformat the code and use tabs instead of spaces while at it.
>
>
Applied to 7.2/scsi-queue, thanks!
[1/1] scsi: scsi_ioctl: use strnlen in scsi_ioctl_get_pci
https://git.kernel.org/mkp/scsi/c/09be9d404f42
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RESEND] scsi: scsi_ioctl: use strnlen in scsi_ioctl_get_pci
2026-05-17 17:15 [PATCH RESEND] scsi: scsi_ioctl: use strnlen in scsi_ioctl_get_pci Thorsten Blum
` (2 preceding siblings ...)
2026-06-02 2:10 ` Martin K. Petersen
@ 2026-06-02 9:19 ` David Laight
3 siblings, 0 replies; 5+ messages in thread
From: David Laight @ 2026-06-02 9:19 UTC (permalink / raw)
To: Thorsten Blum
Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi,
linux-kernel
On Sun, 17 May 2026 19:15:47 +0200
Thorsten Blum <thorsten.blum@linux.dev> wrote:
> Use strnlen() to limit string scanning to 20 characters.
Should that code write the trailing '\0'?
Looks like it has been broken since 2.6.29.
Prior to that it always wrote 20 bytes (changing from 8 bytes in 2.5.0)
I think it needs:
char buf[20];
int len = strscpy(buf, name);
if (copy_to_user(arg, buf, len < 0 ? sizeof (buf) : len + 1))
return -EFAULT;
-- David
>
> Reformat the code and use tabs instead of spaces while at it.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> drivers/scsi/scsi_ioctl.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
> index 0ddc95bafc71..d98c2f19b1e9 100644
> --- a/drivers/scsi/scsi_ioctl.c
> +++ b/drivers/scsi/scsi_ioctl.c
> @@ -176,10 +176,11 @@ static int scsi_ioctl_get_pci(struct scsi_device *sdev, void __user *arg)
>
> name = dev_name(dev);
>
> - /* compatibility with old ioctl which only returned
> - * 20 characters */
> - return copy_to_user(arg, name, min(strlen(name), (size_t)20))
> - ? -EFAULT: 0;
> + /* compatibility with old ioctl which only returned 20 characters */
> + if (copy_to_user(arg, name, strnlen(name, 20)))
> + return -EFAULT;
> +
> + return 0;
> }
>
> static int sg_get_version(int __user *p)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-06-02 9:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-17 17:15 [PATCH RESEND] scsi: scsi_ioctl: use strnlen in scsi_ioctl_get_pci Thorsten Blum
2026-05-18 7:29 ` John Garry
2026-05-23 1:13 ` Martin K. Petersen
2026-06-02 2:10 ` Martin K. Petersen
2026-06-02 9:19 ` David Laight
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox