[PATCH RESEND] scsi: scsi_ioctl: use strnlen in scsi_ioctl_get_pci

Thorsten Blum posted 1 patch 1 week ago
drivers/scsi/scsi_ioctl.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
[PATCH RESEND] scsi: scsi_ioctl: use strnlen in scsi_ioctl_get_pci
Posted by Thorsten Blum 1 week ago
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)
Re: [PATCH RESEND] scsi: scsi_ioctl: use strnlen in scsi_ioctl_get_pci
Posted by Martin K. Petersen 2 days, 4 hours ago
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
Re: [PATCH RESEND] scsi: scsi_ioctl: use strnlen in scsi_ioctl_get_pci
Posted by John Garry 6 days, 22 hours ago
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)
>