pds_core: fix potential stack info leak in firmware version reporting
Subsystems (3)
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.
--- 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
@@ -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
Jakub Kicinski
maintainerQuoted 9 lines · On Fri, 15 May 2026 21:29:06 +0000 Nikhil P. Rao wrote:
The
fw_versionfield inpds_core_fw_name_infois a fixed 32-byte array that may not be null-terminated if firmware writes exactly 32 characters. When passed todevlink_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
Quoted 12 lines · Jakub Kicinski
Quoted 9 lines · On Fri, 15 May 2026 21:29:06 +0000 Nikhil P. Rao wrote:
The
fw_versionfield inpds_core_fw_name_infois a fixed 32-byte array that may not be null-terminated if firmware writes exactly 32 characters. When passed todevlink_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