Skip to contentSkip to conversation

pds_core: limit loop over fw name list

PATCH Applied Shannon Nelson 5 participants 5 messages Jan 3, 2025 – Jan 7, 2025

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

PATCH 1/1 pds_core: limit loop over fw name list

Add an array size limit to the for-loop to be sure we don't try to reference a fw_version string off the end of the fw info names array. We know that our firmware only has a limited number of firmware slot names, but we shouldn't leave this unchecked.

Fixes 45d76f492938 ("pds_core: set up device and adminq")
---
 drivers/net/ethernet/amd/pds_core/devlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/amd/pds_core/devlink.c +1 -1
index 2681889162a2..44971e71991f 100644
@@ -118,7 +118,7 @@ int pdsc_dl_info_get(struct devlink *dl, struct devlink_info_req *req,
 	if (err && err != -EIO)
 		return err;
 
-	listlen = fw_list.num_fw_slots;
+	listlen = min(fw_list.num_fw_slots, ARRAY_SIZE(fw_list.fw_names));
 	for (i = 0; i < listlen; i++) {
 		if (i < ARRAY_SIZE(fw_slotnames))
 			strscpy(buf, fw_slotnames[i], sizeof(buf));
Signature · 1 line
2.17.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Shannon Nelson

Add an array size limit to the for-loop to be sure we don't try to reference a fw_version string off the end of the fw info names array. We know that our firmware only has a limited number of firmware slot names, but we shouldn't leave this unchecked.

Fixes 45d76f492938 ("pds_core: set up device and adminq")
Reviewed-by on v1 1/1
#2 lore raw
In reply to Shannon Nelson
Quoted 16 lines · Shannon Nelson

Add an array size limit to the for-loop to be sure we don't try to reference a fw_version string off the end of the fw info names array. We know that our firmware only has a limited number of firmware slot names, but we shouldn't leave this unchecked.

Fixes 45d76f492938 ("pds_core: set up device and adminq")
---
  drivers/net/ethernet/amd/pds_core/devlink.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/amd/pds_core/devlink.c +0 -0
index 2681889162a2..44971e71991f 100644

drivers/net/ethernet/amd/pds_core/devlink.c int pdsc_dl_info_get(struct devlink *dl, struct devlink_info_req *req, · line 121

Quoted 5 lines
drivers/net/ethernet/amd/pds_core/devlink.c +1 -1
@@ -118,7 +118,7 @@ int pdsc_dl_info_get(struct devlink *dl, struct devlink_info_req *req,
  	if (err && err != -EIO)
  		return err;
 
-	listlen = fw_list.num_fw_slots;
+	listlen = min(fw_list.num_fw_slots, ARRAY_SIZE(fw_list.fw_names));

LGTM. Thanks!

Quoted 3 lines
drivers/net/ethernet/amd/pds_core/devlink.c +0 -0
  	for (i = 0; i < listlen; i++) {
  		if (i < ARRAY_SIZE(fw_slotnames))
  			strscpy(buf, fw_slotnames[i], sizeof(buf));
Reviewed-by on v1 1/1
#3 lore raw
In reply to Shannon Nelson
Quoted 28 lines

-----Original Message-----
From: Shannon Nelson <[email protected]>
Sent: Friday, January 3, 2025 11:52 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Keller, Jacob E <[email protected]>
Cc: [email protected]; Shannon Nelson <[email protected]>
Subject: [PATCH net] pds_core: limit loop over fw name list

Add an array size limit to the for-loop to be sure we don't try to reference a fw_version string off the end of the fw info names array. We know that our firmware only has a limited number of firmware slot names, but we shouldn't leave this unchecked.

Fixes 45d76f492938 ("pds_core: set up device and adminq")
---
 drivers/net/ethernet/amd/pds_core/devlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/amd/pds_core/devlink.c +0 -0
index 2681889162a2..44971e71991f 100644

drivers/net/ethernet/amd/pds_core/devlink.c int pdsc_dl_info_get(struct devlink *dl, struct · line 122

Quoted 6 lines
drivers/net/ethernet/amd/pds_core/devlink.c +1 -1
@@ -118,7 +118,7 @@ int pdsc_dl_info_get(struct devlink *dl, struct
 devlink_info_req *req,
 	if (err && err != -EIO)
 		return err;
 
-	listlen = fw_list.num_fw_slots;
+	listlen = min(fw_list.num_fw_slots, ARRAY_SIZE(fw_list.fw_names));

I assume num_fw_slots comes from the firmware? Makes sense to ensure we limit in case somehow the value no longer matches in the future.

Thanks,
Jake

#4 lore raw
In reply to Shannon Nelson
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Fri, 3 Jan 2025 11:51:47 -0800 you wrote:

Add an array size limit to the for-loop to be sure we don't try to reference a fw_version string off the end of the fw info names array. We know that our firmware only has a limited number of firmware slot names, but we shouldn't leave this unchecked.

Fixes 45d76f492938 ("pds_core: set up device and adminq")

[...]

Here is the summary with links:
- [net] pds_core: limit loop over fw name list

    https://git.kernel.org/netdev/net/c/8c817eb26230

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html