Skip to contentSkip to conversation

drm/amdgpu: : Fix the null pointer dereference for amdgpu_device_switch_gang

PATCH NAK Bob Zhou 2 participants 4 messages Jul 3, 2024

Subsystems (2)
lore
Share & tools
lore

Bob Zhou

author
#0 lore raw

PATCH 1/1 drm/amdgpu: : Fix the null pointer dereference for amdgpu_device_switch_gang

To avoid null pointer dereference reported by Coverity,
so add null pointer check for the return of amdgpu_device_get_gang().

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
index bcacf2e35eba..c1d82c346daa 100644
@@ -6569,7 +6569,7 @@ struct dma_fence *amdgpu_device_switch_gang(struct amdgpu_device *adev,
 		if (old == gang)
 			break;
 
-		if (!dma_fence_is_signaled(old))
+		if (!old || !dma_fence_is_signaled(old))
 			return old;
 
 	} while (cmpxchg((struct dma_fence __force **)&adev->gang_submit,
Signature · 1 line
2.34.1
maintainer NAK
#1 lore raw

Am 03.07.24 um 11:01 schrieb Bob Zhou:

Quoted 2 lines

To avoid null pointer dereference reported by Coverity,
so add null pointer check for the return of amdgpu_device_get_gang().

NAK, that's complete nonsense in the first place.

The pointer is guaranteed to be never NULL or otherwise the logic would have crashed long before.

Regards,
Christian.

Quoted 19 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
index bcacf2e35eba..c1d82c346daa 100644
@@ -6569,7 +6569,7 @@ struct dma_fence *amdgpu_device_switch_gang(struct amdgpu_device *adev,
  		if (old == gang)
  			break;
 
-		if (!dma_fence_is_signaled(old))
+		if (!old || !dma_fence_is_signaled(old))
  			return old;
 
  	} while (cmpxchg((struct dma_fence __force **)&adev->gang_submit,
author NAK
#2 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Christian

Thanks for your comments.
I miss the before logic has limited the generated pointer.

Regards,
Bob

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: 2024年7月3日 17:26
To: Zhou, Bob <[email protected]>; [email protected]; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: : Fix the null pointer dereference for amdgpu_device_switch_gang

Am 03.07.24 um 11:01 schrieb Bob Zhou:

Quoted 2 lines

To avoid null pointer dereference reported by Coverity, so add null pointer check for the return of amdgpu_device_get_gang().

NAK, that's complete nonsense in the first place.

The pointer is guaranteed to be never NULL or otherwise the logic would have crashed long before.

Regards,
Christian.

Quoted 20 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
index bcacf2e35eba..c1d82c346daa 100644
@@ -6569,7 +6569,7 @@ struct dma_fence *amdgpu_device_switch_gang(struct amdgpu_device *adev,
              if (old == gang)
                      break;
 
-             if (!dma_fence_is_signaled(old))
+             if (!old || !dma_fence_is_signaled(old))
                      return old;
 
      } while (cmpxchg((struct dma_fence __force **)&adev->gang_submit,
maintainer
#3 lore raw

Well Coverity probably can't know that and will keep complaining.

Maybe we can add some extra code to point out that old can never be NULL here?

Regards,
Christian.

Am 03.07.24 um 13:06 schrieb Zhou, Bob:

Quoted 46 lines

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Christian

Thanks for your comments.
I miss the before logic has limited the generated pointer.

Regards,
Bob

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: 2024年7月3日 17:26
To: Zhou, Bob <[email protected]>; [email protected]; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: : Fix the null pointer dereference for amdgpu_device_switch_gang

Am 03.07.24 um 11:01 schrieb Bob Zhou:

Quoted 2 lines

To avoid null pointer dereference reported by Coverity, so add null pointer check for the return of amdgpu_device_get_gang().

NAK, that's complete nonsense in the first place.

The pointer is guaranteed to be never NULL or otherwise the logic would have crashed long before.

Regards,
Christian.

Quoted 19 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
index bcacf2e35eba..c1d82c346daa 100644
@@ -6569,7 +6569,7 @@ struct dma_fence *amdgpu_device_switch_gang(struct amdgpu_device *adev,
               if (old == gang)
                       break;
 
-             if (!dma_fence_is_signaled(old))
+             if (!old || !dma_fence_is_signaled(old))
                       return old;
 
       } while (cmpxchg((struct dma_fence __force **)&adev->gang_submit,