Skip to contentSkip to conversation

pds_core: fix potential stack info leak in firmware version reporting

PATCH In review Nikhil P. Rao 3 participants 3 messages May 15 – May 20

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

PATCH 1/1 pds_core: fix potential stack info leak in firmware version reporting

The fw_version field in pds_core_fw_name_info is a fixed 32-byte array that may not be null-terminated if firmware writes exactly 32 characters. When passed to devlink_info_version_stored_put(), this could cause a read beyond the array boundary, potentially leaking stack contents to userspace or causing a crash if the read crosses into an unmapped page.

Null-terminate the firmware version string in place before passing it to the devlink API.

Fixes 45d76f492938 ("pds_core: set up device and adminq")
Assisted-by Claude:claude-opus-4
---
 drivers/net/ethernet/amd/pds_core/devlink.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/amd/pds_core/devlink.c +4 -2
index b576be626a29..3f0e56b951bf 100644
@@ -122,12 +122,14 @@ int pdsc_dl_info_get(struct devlink *dl, struct devlink_info_req *req,
 
 	listlen = min(fw_list.num_fw_slots, ARRAY_SIZE(fw_list.fw_names));
 	for (i = 0; i < listlen; i++) {
+		char *fw_ver = fw_list.fw_names[i].fw_version;
+
 		if (i < ARRAY_SIZE(fw_slotnames))
 			strscpy(buf, fw_slotnames[i], sizeof(buf));
 		else
 			snprintf(buf, sizeof(buf), "fw.slot_%d", i);
-		err = devlink_info_version_stored_put(req, buf,
-						      fw_list.fw_names[i].fw_version);
+		fw_ver[sizeof(fw_list.fw_names[i].fw_version) - 1] = '\0';
+		err = devlink_info_version_stored_put(req, buf, fw_ver);
 		if (err)
 			return err;
 	}
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 9 lines · On Fri, 15 May 2026 21:29:06 +0000 Nikhil P. Rao wrote:

The fw_version field in pds_core_fw_name_info is a fixed 32-byte array that may not be null-terminated if firmware writes exactly 32 characters. When passed to devlink_info_version_stored_put(), this could cause a read beyond the array boundary, potentially leaking stack contents to userspace or causing a crash if the read crosses into an unmapped page.

Null-terminate the firmware version string in place before passing it to the devlink API.

This loses the last, presumably meaningful character of the FW version. Are you saying that device should never send names this long and this is defensive? Otherwise we could trivially memcpy() the name into a buffer on the stack that has one extra byte.

Please fix or clarify the commit msg.

Signature · 1 line
pw-bot: cr
#2 lore raw
Quoted 12 lines · Jakub Kicinski
Quoted 9 lines · On Fri, 15 May 2026 21:29:06 +0000 Nikhil P. Rao wrote:

The fw_version field in pds_core_fw_name_info is a fixed 32-byte array that may not be null-terminated if firmware writes exactly 32 characters. When passed to devlink_info_version_stored_put(), this could cause a read beyond the array boundary, potentially leaking stack contents to userspace or causing a crash if the read crosses into an unmapped page.

Null-terminate the firmware version string in place before passing it to the devlink API.

Quoted 6 lines

This loses the last, presumably meaningful character of the FW version. Are you saying that device should never send names this long and this is defensive? Otherwise we could trivially memcpy() the name into a buffer on the stack that has one extra byte.

Please fix or clarify the commit msg.

Thanks for the review.

The firmware already null-terminates these strings, so the fix won't truncate any valid data. This is a defensive fix - the driver shouldn't rely on firmware behavior.

I'll send v2 with an updated commit message that clarifies this.

Nikhil