* [PATCH] scsi: bfa: Replace kzalloc + copy_from_user with memdup_user
@ 2025-09-18 14:40 Thorsten Blum
2025-09-25 2:10 ` Martin K. Petersen
0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Blum @ 2025-09-18 14:40 UTC (permalink / raw)
To: Anil Gurumurthy, Sudarsana Kalluru, James E.J. Bottomley,
Martin K. Petersen
Cc: Thorsten Blum, linux-scsi, linux-kernel
Replace kzalloc() followed by copy_from_user() with memdup_user() to
improve and simplify bfad_im_bsg_els_ct_request(). memdup_user() returns
either -ENOMEM or -EFAULT (instead of -EIO) if an error occurs.
Use u64_to_user_ptr() instead of manually casting 'bsg_data->payload'.
No functional changes intended other than returning the more idiomatic
error code -EFAULT.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
drivers/scsi/bfa/bfad_bsg.c | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index 54bd11e6d593..d90dfee95160 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3392,21 +3392,10 @@ bfad_im_bsg_els_ct_request(struct bsg_job *job)
if (bsg_data == NULL)
goto out;
- /*
- * Allocate buffer for bsg_fcpt and do a copy_from_user op for payload
- * buffer of size bsg_data->payload_len
- */
- bsg_fcpt = kzalloc(bsg_data->payload_len, GFP_KERNEL);
- if (!bsg_fcpt) {
- rc = -ENOMEM;
- goto out;
- }
-
- if (copy_from_user((uint8_t *)bsg_fcpt,
- (void *)(unsigned long)bsg_data->payload,
- bsg_data->payload_len)) {
- kfree(bsg_fcpt);
- rc = -EIO;
+ bsg_fcpt = memdup_user(u64_to_user_ptr(bsg_data->payload),
+ bsg_data->payload_len);
+ if (IS_ERR(bsg_fcpt)) {
+ rc = PTR_ERR(bsg_fcpt);
goto out;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] scsi: bfa: Replace kzalloc + copy_from_user with memdup_user
2025-09-18 14:40 [PATCH] scsi: bfa: Replace kzalloc + copy_from_user with memdup_user Thorsten Blum
@ 2025-09-25 2:10 ` Martin K. Petersen
2025-09-25 18:13 ` Thorsten Blum
0 siblings, 1 reply; 4+ messages in thread
From: Martin K. Petersen @ 2025-09-25 2:10 UTC (permalink / raw)
To: Thorsten Blum
Cc: Anil Gurumurthy, Sudarsana Kalluru, James E.J. Bottomley,
Martin K. Petersen, linux-scsi, linux-kernel
Thorsten,
> No functional changes intended other than returning the more idiomatic
> error code -EFAULT.
How can we be sure that this doesn't break existing applications?
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: bfa: Replace kzalloc + copy_from_user with memdup_user
2025-09-25 2:10 ` Martin K. Petersen
@ 2025-09-25 18:13 ` Thorsten Blum
2025-09-29 20:49 ` Martin K. Petersen
0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Blum @ 2025-09-25 18:13 UTC (permalink / raw)
To: Martin K. Petersen
Cc: Anil Gurumurthy, Sudarsana Kalluru, James E.J. Bottomley,
linux-scsi, linux-kernel
Hi Martin,
On 25. Sep 2025, at 04:10, Martin K. Petersen wrote:
>
>> No functional changes intended other than returning the more idiomatic
>> error code -EFAULT.
>
> How can we be sure that this doesn't break existing applications?
I guess we can't because the error code is returned to userspace as the
result of a bsg_job? That wasn't immediately obvious to me.
Thanks,
Thorsten
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: bfa: Replace kzalloc + copy_from_user with memdup_user
2025-09-25 18:13 ` Thorsten Blum
@ 2025-09-29 20:49 ` Martin K. Petersen
0 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2025-09-29 20:49 UTC (permalink / raw)
To: Thorsten Blum
Cc: Martin K. Petersen, Anil Gurumurthy, Sudarsana Kalluru,
James E.J. Bottomley, linux-scsi, linux-kernel
Hi Thorsten!
>>> No functional changes intended other than returning the more
>>> idiomatic error code -EFAULT.
>>
>> How can we be sure that this doesn't break existing applications?
>
> I guess we can't because the error code is returned to userspace as
> the result of a bsg_job? That wasn't immediately obvious to me.
Correct. And with little chance of having the associated management
utilities updated, it's best to leave things as they are.
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-29 20:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-18 14:40 [PATCH] scsi: bfa: Replace kzalloc + copy_from_user with memdup_user Thorsten Blum
2025-09-25 2:10 ` Martin K. Petersen
2025-09-25 18:13 ` Thorsten Blum
2025-09-29 20:49 ` 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