* [PATCH] scsi: smartpqi: Replace kmalloc + copy_from_user with memdup_user
@ 2025-09-22 20:18 Thorsten Blum
2025-09-23 16:17 ` Don.Brace
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Thorsten Blum @ 2025-09-22 20:18 UTC (permalink / raw)
To: Don Brace, James E.J. Bottomley, Martin K. Petersen
Cc: Thorsten Blum, storagedev, linux-scsi, linux-kernel
Replace kmalloc() followed by copy_from_user() with memdup_user() to
simplify and improve pqi_passthru_ioctl().
Since memdup_user() already allocates memory, use kzalloc() in the else
branch instead of manually zeroing 'kernel_buffer' using memset(0).
Return early if an error occurs. No functional changes intended.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
drivers/scsi/smartpqi/smartpqi_init.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
index 125944941601..03c97e60d36f 100644
--- a/drivers/scsi/smartpqi/smartpqi_init.c
+++ b/drivers/scsi/smartpqi/smartpqi_init.c
@@ -20,6 +20,7 @@
#include <linux/reboot.h>
#include <linux/cciss_ioctl.h>
#include <linux/crash_dump.h>
+#include <linux/string.h>
#include <scsi/scsi_host.h>
#include <scsi/scsi_cmnd.h>
#include <scsi/scsi_device.h>
@@ -6774,17 +6775,15 @@ static int pqi_passthru_ioctl(struct pqi_ctrl_info *ctrl_info, void __user *arg)
}
if (iocommand.buf_size > 0) {
- kernel_buffer = kmalloc(iocommand.buf_size, GFP_KERNEL);
- if (!kernel_buffer)
- return -ENOMEM;
if (iocommand.Request.Type.Direction & XFER_WRITE) {
- if (copy_from_user(kernel_buffer, iocommand.buf,
- iocommand.buf_size)) {
- rc = -EFAULT;
- goto out;
- }
+ kernel_buffer = memdup_user(iocommand.buf,
+ iocommand.buf_size);
+ if (IS_ERR(kernel_buffer))
+ return PTR_ERR(kernel_buffer);
} else {
- memset(kernel_buffer, 0, iocommand.buf_size);
+ kernel_buffer = kzalloc(iocommand.buf_size, GFP_KERNEL);
+ if (!kernel_buffer)
+ return -ENOMEM;
}
}
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] scsi: smartpqi: Replace kmalloc + copy_from_user with memdup_user
2025-09-22 20:18 [PATCH] scsi: smartpqi: Replace kmalloc + copy_from_user with memdup_user Thorsten Blum
@ 2025-09-23 16:17 ` Don.Brace
2025-09-25 1:31 ` Martin K. Petersen
2025-09-30 2:36 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Don.Brace @ 2025-09-23 16:17 UTC (permalink / raw)
To: thorsten.blum, James.Bottomley, martin.petersen
Cc: storagedev, linux-scsi, linux-kernel
________________________________________
From: Thorsten Blum <thorsten.blum@linux.dev>
Sent: Monday, September 22, 2025 3:18 PM
To: Don Brace - C33706 <Don.Brace@microchip.com>; James E.J. Bottomley <James.Bottomley@HansenPartnership.com>; Martin K. Petersen <martin.petersen@oracle.com>
Cc: Thorsten Blum <thorsten.blum@linux.dev>; storagedev <storagedev@microchip.com>; linux-scsi@vger.kernel.org <linux-scsi@vger.kernel.org>; linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>
Subject: [PATCH] scsi: smartpqi: Replace kmalloc + copy_from_user with memdup_user
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Replace kmalloc() followed by copy_from_user() with memdup_user() to
simplify and improve pqi_passthru_ioctl().
Since memdup_user() already allocates memory, use kzalloc() in the else
branch instead of manually zeroing 'kernel_buffer' using memset(0).
Return early if an error occurs. No functional changes intended.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
Acked-by: Don Brace <don.brace@microchip.com>
Sorry about duplicate e-mail, forgot to switch to text-only.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: smartpqi: Replace kmalloc + copy_from_user with memdup_user
2025-09-22 20:18 [PATCH] scsi: smartpqi: Replace kmalloc + copy_from_user with memdup_user Thorsten Blum
2025-09-23 16:17 ` Don.Brace
@ 2025-09-25 1:31 ` Martin K. Petersen
2025-09-30 2:36 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2025-09-25 1:31 UTC (permalink / raw)
To: Thorsten Blum
Cc: Don Brace, James E.J. Bottomley, Martin K. Petersen, storagedev,
linux-scsi, linux-kernel
Thorsten,
> Replace kmalloc() followed by copy_from_user() with memdup_user() to
> simplify and improve pqi_passthru_ioctl().
>
> Since memdup_user() already allocates memory, use kzalloc() in the
> else branch instead of manually zeroing 'kernel_buffer' using
> memset(0).
>
> Return early if an error occurs. No functional changes intended.
Applied to 6.18/scsi-staging, thanks!
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: smartpqi: Replace kmalloc + copy_from_user with memdup_user
2025-09-22 20:18 [PATCH] scsi: smartpqi: Replace kmalloc + copy_from_user with memdup_user Thorsten Blum
2025-09-23 16:17 ` Don.Brace
2025-09-25 1:31 ` Martin K. Petersen
@ 2025-09-30 2:36 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2025-09-30 2:36 UTC (permalink / raw)
To: Don Brace, James E.J. Bottomley, Thorsten Blum
Cc: Martin K . Petersen, storagedev, linux-scsi, linux-kernel
On Mon, 22 Sep 2025 22:18:33 +0200, Thorsten Blum wrote:
> Replace kmalloc() followed by copy_from_user() with memdup_user() to
> simplify and improve pqi_passthru_ioctl().
>
> Since memdup_user() already allocates memory, use kzalloc() in the else
> branch instead of manually zeroing 'kernel_buffer' using memset(0).
>
> Return early if an error occurs. No functional changes intended.
>
> [...]
Applied to 6.18/scsi-queue, thanks!
[1/1] scsi: smartpqi: Replace kmalloc + copy_from_user with memdup_user
https://git.kernel.org/mkp/scsi/c/0ac3c901fbeb
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-30 4:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-22 20:18 [PATCH] scsi: smartpqi: Replace kmalloc + copy_from_user with memdup_user Thorsten Blum
2025-09-23 16:17 ` Don.Brace
2025-09-25 1:31 ` Martin K. Petersen
2025-09-30 2:36 ` 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