scsi: Use kmalloc_array to prevent overflow of dynamic size calculation
Subsystems (2)
PATCH 1/1 scsi: Use kmalloc_array to prevent overflow of dynamic size calculation
Use kmalloc_array to avoid potential overflow during dynamic size calculation inside kmalloc.
--- drivers/scsi/smartpqi/smartpqi_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/smartpqi/smartpqi_init.c +1 -1
@@ -8937,7 +8937,7 @@ static int pqi_host_alloc_mem(struct pqi_ctrl_info *ctrl_info,if (sg_count ==0 || sg_count >PQI_HOST_MAX_SG_DESCRIPTORS ) goto out; - host_memory_descriptor->host_chunk_virt_address =kmalloc (sg_count *sizeof (void *),GFP_KERNEL ); + host_memory_descriptor->host_chunk_virt_address =kmalloc_array (sg_count,sizeof (void *),GFP_KERNEL );if (!host_memory_descriptor->host_chunk_virt_address) goto out;
Signature · 1 line
2.34.1
From: Bhanu Seshu Kumar Valluri <[email protected]>
Sent: Wednesday, October 1, 2025 6:39 AM
To: Don Brace - C33706 <[email protected]>; James E . J . Bottomley <[email protected]>; Martin K . Petersen <[email protected]>; storagedev <[email protected]>
Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> Subject: [PATCH] scsi: Use kmalloc_array to prevent overflow of dynamic size calculation
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Use kmalloc_array to avoid potential overflow during dynamic size calculation inside kmalloc.
Thanks for your patch,
Don
---
drivers/scsi/smartpqi/smartpqi_init.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/smartpqi/smartpqi_init.c +0 -0
@@ -8937,7 +8937,7 @@ static int pqi_host_alloc_mem(struct pqi_ctrl_info *ctrl_info,
if (sg_count == 0 || sg_count > PQI_HOST_MAX_SG_DESCRIPTORS) goto out;
- host_memory_descriptor->host_chunk_virt_address = kmalloc(sg_count * sizeof(void *), GFP_KERNEL); + host_memory_descriptor->host_chunk_virt_address = kmalloc_array(sg_count, sizeof(void *), GFP_KERNEL); if (!host_memory_descriptor->host_chunk_virt_address)
goto out;
--
2.34.1
James Bottomley
maintainerQuoted 2 lines · Bhanu Seshu Kumar Valluri
Use
kmalloc_arrayto avoid potential overflow during dynamic size calculation inside kmalloc.
This description isn't correct.
Quoted 12 lines
Signed-off-by Bhanu Seshu Kumar Valluri <[email protected]>---
drivers/scsi/smartpqi/smartpqi_init.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/scsi/smartpqi/smartpqi_init.c +0
-0
drivers/scsi/smartpqi/smartpqi_init.c static int pqi_host_alloc_mem(struct · line 8939
Quoted 3 lines
drivers/scsi/smartpqi/smartpqi_init.c +0
-0@@ -8937,7 +8937,7 @@ static int pqi_host_alloc_mem(struct pqi_ctrl_info *ctrl_info, if (sg_count == 0 || sg_count > PQI_HOST_MAX_SG_DESCRIPTORS) goto out;
Given this check
Quoted 3 lines
drivers/scsi/smartpqi/smartpqi_init.c +0
-1- host_memory_descriptor->host_chunk_virt_address =
kmalloc(sg_count * sizeof(void *), GFP_KERNEL);
How is it possible that this allocation could ever overflow?
If you want to change the description to say using kmalloc_array is better practice or something (and the maintainer concurs) that's fine, but we can't have a false justification in the kernel git log.
Regards,
James
Quoted 14 lines · James Bottomley
Quoted 2 lines · Bhanu Seshu Kumar Valluri
Use
kmalloc_arrayto avoid potential overflow during dynamic size calculation inside kmalloc.This description isn't correct.
Given this check
Quoted 3 lines
(quoted diff) +0
-1- host_memory_descriptor->host_chunk_virt_address =
kmalloc(sg_count * sizeof(void *), GFP_KERNEL);How is it possible that this allocation could ever overflow?
Quoted 8 lines
If you want to change the description to say using
kmalloc_arrayis better practice or something (and the maintainer concurs) that's fine, but we can't have a false justification in the kernel git log.Regards,
James
Hi,
Thank you for your helpful comment.
I will await till maintainer confirms if it is ok to push this change as v2 with subject line similar what you have suggested.
Regards,
Bhanu Seshu Kumar Valluri
Quoted 21 lines · Bhanu Seshu Kumar Valluri
Quoted 20 lines · James Bottomley
Quoted 2 lines · Bhanu Seshu Kumar Valluri
Use
kmalloc_arrayto avoid potential overflow during dynamic size calculation inside kmalloc.This description isn't correct.
Given this check
Quoted 3 lines
(quoted diff) +0
-1- host_memory_descriptor->host_chunk_virt_address =
kmalloc(sg_count * sizeof(void *), GFP_KERNEL);How is it possible that this allocation could ever overflow?
If you want to change the description to say using
kmalloc_arrayis better practice or something (and the maintainer concurs) that's fine, but we can't have a false justification in the kernel git log.Regards,
Quoted 7 lines
Quoted 2 lines
James
Hi,
Thank you for your helpful comment.
I will await till maintainer confirms if it is ok to push this change as v2 with subject line similar what you have suggested.
You misinterpreted James' reply ("and the maintainer concurs").
James is one of the two SCSI maintainers, so there is no need to delay sending a V2.
Kind regards,
Niklas
Quoted 26 lines · Niklas Cassel
Quoted 25 lines · Bhanu Seshu Kumar Valluri
Quoted 14 lines · James Bottomley
Quoted 2 lines · Bhanu Seshu Kumar Valluri
Use
kmalloc_arrayto avoid potential overflow during dynamic size calculation inside kmalloc.This description isn't correct.
Given this check
Quoted 3 lines
(quoted diff) +0
-1- host_memory_descriptor->host_chunk_virt_address =
kmalloc(sg_count * sizeof(void *), GFP_KERNEL);How is it possible that this allocation could ever overflow?
Quoted 8 lines
If you want to change the description to say using
kmalloc_arrayis better practice or something (and the maintainer concurs) that's fine, but we can't have a false justification in the kernel git log.Regards,
James
Hi,
Quoted 8 lines
Quoted 3 lines
Thank you for your helpful comment.
I will await till maintainer confirms if it is ok to push this change as v2 with subject line similar what you have suggested.You misinterpreted James' reply ("and the maintainer concurs").
James is one of the two SCSI maintainers, so there is no need to delay sending a V2.
Hi Niklas,
Thanks for clarifying that. I will send v2 patch.
Regards,
Bhanu Seshu Kumar Valluri