Skip to contentSkip to conversation

scsi: Use kmalloc_array to prevent overflow of dynamic size calculation

PATCH In review Bhanu Seshu Kumar Valluri 4 participants 6 messages Oct 1, 2025 – Oct 7, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 125944941601..7ff39f1faf38 100644
@@ -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
maintainer Acked-by on v1 1/1
#1 lore raw

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
index 125944941601..7ff39f1faf38 100644
@@ -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

maintainer
#2 lore raw
In reply to Bhanu Seshu Kumar Valluri
Quoted 2 lines · Bhanu Seshu Kumar Valluri

Use kmalloc_array to avoid potential overflow during dynamic size calculation inside kmalloc.

This description isn't correct.

Quoted 12 lines

---
 drivers/scsi/smartpqi/smartpqi_init.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/smartpqi/smartpqi_init.c +0 -0
index 125944941601..7ff39f1faf38 100644

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

#3 lore raw
Quoted 14 lines · James Bottomley
Quoted 2 lines · Bhanu Seshu Kumar Valluri

Use kmalloc_array to 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_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

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

#4 lore raw
Quoted 21 lines · Bhanu Seshu Kumar Valluri
Quoted 20 lines · James Bottomley
Quoted 2 lines · Bhanu Seshu Kumar Valluri

Use kmalloc_array to 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_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,

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

#5 lore raw
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_array to 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_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

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