]> www.infradead.org Git - users/hch/misc.git/commitdiff
pds_core: limit loop over fw name list
authorShannon Nelson <shannon.nelson@amd.com>
Fri, 3 Jan 2025 19:51:47 +0000 (11:51 -0800)
committerJakub Kicinski <kuba@kernel.org>
Mon, 6 Jan 2025 23:57:54 +0000 (15:57 -0800)
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")
Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Reviewed-by: Brett Creeley <brett.creeley@amd.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Link: https://patch.msgid.link/20250103195147.7408-1-shannon.nelson@amd.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/amd/pds_core/devlink.c

index 2681889162a25e000d9c636de3fcc52093252238..44971e71991ff5ff4c51c64cea9d0a0f8b337494 100644 (file)
@@ -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));