Skip to contentSkip to conversation

drm/amdgpu: Fix the out-of-bounds read warning

PATCH In review Ma Jun 4 participants 6 messages Apr 22, 2024 – Apr 23, 2024

Subsystems (2)
lore
Share & tools
lore

Ma Jun

author
#0 lore raw

PATCH 1/3 drm/amdgpu: Fix the out-of-bounds read warning

Use '<' instead of '<=' to fix the out-of-bounds
read error

---
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +1 -1
index eb25af46622e..5c08ad234439 100644
@@ -144,7 +144,7 @@ static const char *mes_v11_0_get_misc_op_string(union MESAPI__MISC *x_pkt)
 	const char *op_str = NULL;
 
 	if ((x_pkt->header.opcode == MES_SCH_API_MISC) &&
-	    (x_pkt->opcode <= ARRAY_SIZE(mes_v11_0_misc_opcodes)))
+	    (x_pkt->opcode < ARRAY_SIZE(mes_v11_0_misc_opcodes)))
 		op_str = mes_v11_0_misc_opcodes[x_pkt->opcode];
 
 	return op_str;
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 2/3 drm/amdgpu: Fix uninitialized variable warnings

return 0 to avoid returning an uninitialized variable r

---
 drivers/gpu/drm/amd/amdgpu/aldebaran.c      | 2 +-
 drivers/gpu/drm/amd/amdgpu/sienna_cichlid.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/aldebaran.c +1 -1
index 576067d66bb9..d0a8da67dc2a 100644
@@ -97,7 +97,7 @@ static int aldebaran_mode2_suspend_ip(struct amdgpu_device *adev)
 		adev->ip_blocks[i].status.hw = false;
 	}
 
-	return r;
+	return 0;
 }
 
 static int
drivers/gpu/drm/amd/amdgpu/sienna_cichlid.c +1 -1
index 93f6772d1b24..481217c32d85 100644
@@ -92,7 +92,7 @@ static int sienna_cichlid_mode2_suspend_ip(struct amdgpu_device *adev)
 		adev->ip_blocks[i].status.hw = false;
 	}
 
-	return r;
+	return 0;
 }
 
 static int
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 3/3 drm/amdgpu: Fix Uninitialized scalar variable warning

In reply to Ma Jun

Initialize the variables which were not initialized to fix the coverity issue "Uninitialized scalar variable"

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -1
index 7e6d09730e6d..7b28b6b8982b 100644
@@ -437,7 +437,7 @@ void amdgpu_irq_dispatch(struct amdgpu_device *adev,
 			 struct amdgpu_ih_ring *ih)
 {
 	u32 ring_index = ih->rptr >> 2;
-	struct amdgpu_iv_entry entry;
+	struct amdgpu_iv_entry entry = {0};
 	unsigned int client_id, src_id;
 	struct amdgpu_irq_src *src;
 	bool handled = false;
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -1
index 924baf58e322..f0a63d084b4d 100644
@@ -1559,7 +1559,7 @@ static int amdgpu_debugfs_firmware_info_show(struct seq_file *m, void *unused)
 {
 	struct amdgpu_device *adev = m->private;
 	struct drm_amdgpu_info_firmware fw_info;
-	struct drm_amdgpu_query_fw query_fw;
+	struct drm_amdgpu_query_fw query_fw = {0};
 	struct atom_context *ctx = adev->mode_info.atom_context;
 	uint8_t smu_program, smu_major, smu_minor, smu_debug;
 	int ret, i;
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +1 -1
index 2b99eed5ba19..41ac3319108b 100644
@@ -120,7 +120,7 @@ static void __amdgpu_xcp_add_block(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id,
 int amdgpu_xcp_init(struct amdgpu_xcp_mgr *xcp_mgr, int num_xcps, int mode)
 {
 	struct amdgpu_device *adev = xcp_mgr->adev;
-	struct amdgpu_xcp_ip ip;
+	struct amdgpu_xcp_ip ip = {0};
 	uint8_t mem_id;
 	int i, j, ret;
 
Signature · 1 line
2.34.1
maintainer
#3 lore raw

Re: [PATCH 3/3] drm/amdgpu: Fix Uninitialized scalar variable warning

Am 22.04.24 um 11:49 schrieb Ma Jun:

Quoted 2 lines

Initialize the variables which were not initialized to fix the coverity issue "Uninitialized scalar variable"

Feel free to add my Acked-by to the first two patches, but this here clearly doesn't looks like a good idea to me.

Quoted 13 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 2 +-
  3 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -0
index 7e6d09730e6d..7b28b6b8982b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_dispatch(struct amdgpu_device *adev, · line 440

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -1
@@ -437,7 +437,7 @@ void amdgpu_irq_dispatch(struct amdgpu_device *adev,
  			 struct amdgpu_ih_ring *ih)
  {
  	u32 ring_index = ih->rptr >> 2;
-	struct amdgpu_iv_entry entry;
+	struct amdgpu_iv_entry entry = {0};

When this needs to be initialized there is clearly something wrong with the code. I would guess similar for the other two.

What exactly does coverity complains about?

Regards,
Christian.

Quoted 29 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -0
  	unsigned int client_id, src_id;
  	struct amdgpu_irq_src *src;
  	bool handled = false;
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -1
index 924baf58e322..f0a63d084b4d 100644
@@ -1559,7 +1559,7 @@ static int amdgpu_debugfs_firmware_info_show(struct seq_file *m, void *unused)
  {
  	struct amdgpu_device *adev = m->private;
  	struct drm_amdgpu_info_firmware fw_info;
-	struct drm_amdgpu_query_fw query_fw;
+	struct drm_amdgpu_query_fw query_fw = {0};
  	struct atom_context *ctx = adev->mode_info.atom_context;
  	uint8_t smu_program, smu_major, smu_minor, smu_debug;
  	int ret, i;
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +1 -1
index 2b99eed5ba19..41ac3319108b 100644
@@ -120,7 +120,7 @@ static void __amdgpu_xcp_add_block(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id,
  int amdgpu_xcp_init(struct amdgpu_xcp_mgr *xcp_mgr, int num_xcps, int mode)
  {
  	struct amdgpu_device *adev = xcp_mgr->adev;
-	struct amdgpu_xcp_ip ip;
+	struct amdgpu_xcp_ip ip = {0};
  	uint8_t mem_id;
  	int i, j, ret;
 
#4 lore raw

Re: [PATCH 3/3] drm/amdgpu: Fix Uninitialized scalar variable warning

Quoted 15 lines · Christian König

Am 22.04.24 um 11:49 schrieb Ma Jun:

Quoted 2 lines

Initialize the variables which were not initialized to fix the coverity issue "Uninitialized scalar variable"

Feel free to add my Acked-by to the first two patches, but this here clearly doesn't looks like a good idea to me.

Quoted 8 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 2 +-
  3 files changed, 3 insertions(+), 3 deletions(-)
Quoted 14 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_dispatch(struct amdgpu_device *adev, · line 440

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -1
index 7e6d09730e6d..7b28b6b8982b 100644
@@ -437,7 +437,7 @@ void amdgpu_irq_dispatch(struct amdgpu_device *adev,
  			 struct amdgpu_ih_ring *ih)
  {
  	u32 ring_index = ih->rptr >> 2;
-	struct amdgpu_iv_entry entry;
+	struct amdgpu_iv_entry entry = {0};

When this needs to be initialized there is clearly something wrong with the code. I would guess similar for the other two.

Yes. Some decode_iv functions did't assign value to entry.timestamp. I will check this.

Quoted 1 line

What exactly does coverity complains about?

Coverity warning:
Using uninitialized value entry.timestamp

Quoted 4 lines

Regards,
Christian.

Quoted 13 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c static int amdgpu_debugfs_firmware_info_show(struct seq_file *m, void *unused) · line 1562

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -0
  	unsigned int client_id, src_id;
  	struct amdgpu_irq_src *src;
  	bool handled = false;
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -1
index 924baf58e322..f0a63d084b4d 100644
@@ -1559,7 +1559,7 @@ static int amdgpu_debugfs_firmware_info_show(struct seq_file *m, void *unused)
  {
  	struct amdgpu_device *adev = m->private;
  	struct drm_amdgpu_info_firmware fw_info;
-	struct drm_amdgpu_query_fw query_fw;
+	struct drm_amdgpu_query_fw query_fw = {0};

Coverity warning:
uninit_use_in_call Using uninitialized value query_fw.index when calling amdgpu_firmware_info

Even though qeuery_fw.index was assigned a value before it's used, there is still an coverity warning. We need to initialize query_fw when declare it.

Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
  	struct atom_context *ctx = adev->mode_info.atom_context;
  	uint8_t smu_program, smu_major, smu_minor, smu_debug;
  	int ret, i;
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +0 -0
index 2b99eed5ba19..41ac3319108b 100644
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c static void __amdgpu_xcp_add_block(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id, · line 123

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +1 -1
@@ -120,7 +120,7 @@ static void __amdgpu_xcp_add_block(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id,
  int amdgpu_xcp_init(struct amdgpu_xcp_mgr *xcp_mgr, int num_xcps, int mode)
  {
  	struct amdgpu_device *adev = xcp_mgr->adev;
-	struct amdgpu_xcp_ip ip;
+	struct amdgpu_xcp_ip ip = {0};

Coverity Warning:
Using uninitialized value ip. Field ip.valid is uninitialized when calling __amdgpu_xcp_add_block

The code is ok. We just need to initialize the variable ip.

Regards,
Ma Jun

Quoted 4 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +0 -0
  	uint8_t mem_id;
  	int i, j, ret;
 
#5 lore raw

Re: [PATCH 3/3] drm/amdgpu: Fix Uninitialized scalar variable warning

Am 23.04.24 um 04:53 schrieb Ma, Jun:

Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
   	unsigned int client_id, src_id;
   	struct amdgpu_irq_src *src;
   	bool handled = false;
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
index 924baf58e322..f0a63d084b4d 100644
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c static int amdgpu_debugfs_firmware_info_show(struct seq_file *m, void *unused) · line 1562

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -1
@@ -1559,7 +1559,7 @@ static int amdgpu_debugfs_firmware_info_show(struct seq_file *m, void *unused)
   {
   	struct amdgpu_device *adev = m->private;
   	struct drm_amdgpu_info_firmware fw_info;
-	struct drm_amdgpu_query_fw query_fw;
+	struct drm_amdgpu_query_fw query_fw = {0};

Coverity warning:
uninit_use_in_call Using uninitialized value query_fw.index when calling amdgpu_firmware_info

Quoted 2 lines

Even though qeuery_fw.index was assigned a value before it's used, there is still an coverity warning. We need to initialize query_fw when declare it.

But initializing it to zero doesn't sounds correct either.

The amdgpu_firmware_info() function is designed to return the FW info for a specific block, if the block isn't specified than coverity is right that we have a coding error here.

Just initializing the value silences coverity but is most likely not the right thing to do.

Regards,
Christian.

Quoted 26 lines
Quoted 14 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
   	struct atom_context *ctx = adev->mode_info.atom_context;
   	uint8_t smu_program, smu_major, smu_minor, smu_debug;
   	int ret, i;
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +0 -0
index 2b99eed5ba19..41ac3319108b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c static void __amdgpu_xcp_add_block(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id, · line 123

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +1 -1
@@ -120,7 +120,7 @@ static void __amdgpu_xcp_add_block(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id,
   int amdgpu_xcp_init(struct amdgpu_xcp_mgr *xcp_mgr, int num_xcps, int mode)
   {
   	struct amdgpu_device *adev = xcp_mgr->adev;
-	struct amdgpu_xcp_ip ip;
+	struct amdgpu_xcp_ip ip = {0};

Coverity Warning:
Using uninitialized value ip. Field ip.valid is uninitialized when calling __amdgpu_xcp_add_block

The code is ok. We just need to initialize the variable ip.

Regards,
Ma Jun

Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +0 -0
   	uint8_t mem_id;
   	int i, j, ret;