Skip to contentSkip to conversation

drm/amdgpu: fix ucode out-of-bounds read warning

PATCH In review Tim Huang 2 participants 4 messages May 6, 2024

Subsystems (2)
lore
Share & tools
lore

Tim Huang

author
#0 lore raw

PATCH 1/2 drm/amdgpu: fix ucode out-of-bounds read warning

Clear warning that read ucode[] may out-of-bounds.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c +3 -0
index b8280be6225d..c3d89088123d 100644
@@ -213,6 +213,9 @@ static int amdgpu_cgs_get_firmware_info(struct cgs_device *cgs_device,
 		struct amdgpu_firmware_info *ucode;
 
 		id = fw_type_convert(cgs_device, type);
+		if (id >= AMDGPU_UCODE_ID_MAXIMUM)
+			return -EINVAL;
+
 		ucode = &adev->firmware.ucode[id];
 		if (ucode->fw == NULL)
 			return -EINVAL;
Signature · 1 line
2.39.2
author
#1 lore raw

PATCH 2/2 drm/amdgpu: fix mc_data out-of-bounds read warning

Clear warning that read mc_data[i-1] may out-of-bounds.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +2 -0
index 52b12c1718eb..7dc102f0bc1d 100644
@@ -1484,6 +1484,8 @@ int amdgpu_atombios_init_mc_reg_table(struct amdgpu_device *adev,
 										(u32)le32_to_cpu(*((u32 *)reg_data + j));
 									j++;
 								} else if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_EQU_PREV) {
+									if (i == 0)
+										continue;
 									reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
 										reg_table->mc_reg_table_entry[num_ranges].mc_data[i - 1];
 								}
Signature · 1 line
2.39.2
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] drm/amdgpu: fix mc_data out-of-bounds read warning

Quoted 4 lines · Tim Huang

Clear warning that read mc_data[i-1] may out-of-bounds.

Quoted 20 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +2 -1
index 52b12c1718eb..7dc102f0bc1d 100644
@@ -1484,6 +1484,8 @@ int amdgpu_atombios_init_mc_reg_table(struct amdgpu_device *adev,
                                                                                (u32)le32_to_cpu(*((u32 *)reg_data + j));
                                                                        j++;
                                                                } else if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_EQU_PREV) {
+                                                                       if (i == 0)
+                                                                               continue;
                                                                        reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
                                                                                reg_table->mc_reg_table_entry[num_ranges].mc_data[i - 1];
                                                                }
--

2.39.2

Reviewed-by on v1 1/2
#3 lore raw
In reply to Tim Huang
Quoted 4 lines · Tim Huang

Clear warning that read ucode[] may out-of-bounds.

Quoted 21 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c +3 -1
index b8280be6225d..c3d89088123d 100644
@@ -213,6 +213,9 @@ static int amdgpu_cgs_get_firmware_info(struct cgs_device *cgs_device,
                struct amdgpu_firmware_info *ucode;
 
                id = fw_type_convert(cgs_device, type);
+               if (id >= AMDGPU_UCODE_ID_MAXIMUM)
+                       return -EINVAL;
+
                ucode = &adev->firmware.ucode[id];
                if (ucode->fw == NULL)
                        return -EINVAL;
--

2.39.2