Skip to contentSkip to conversation

drm/i915/gvt: Fix NULL pointer dereference in slot switch

PATCH In review Tuo Li 3 participants 4 messages Nov 12 – Nov 17

Subsystems (3)
lore
Share & tools
lore

Tuo Li

author
#0 lore raw

PATCH 1/1 drm/i915/gvt: Fix NULL pointer dereference in slot switch

The running slot is updated to the pending slot before updating the running context. However, the condition checks the old running context instead of the newly assigned running slot.

When no pending slot exists, running_slot becomes NULL. If the previous running_context is non-NULL, the code attempts to access running_slot->ctx[0], resulting in a NULL pointer dereference.

To fix this possible NULL pointer dereference, check running_slot instead to ensure that running_context is updated only when a valid slot is available.

Fixes 8453d674ae7e ("drm/i915/gvt: vGPU execlist virtualization")
---
 drivers/gpu/drm/i915/gvt/execlist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/gvt/execlist.c +1 -1
index 29147a9f162e..763c310f2aaf 100644
@@ -73,7 +73,7 @@ static void switch_virtual_execlist_slot(struct intel_vgpu_execlist *execlist)
 
 	execlist->running_slot = execlist->pending_slot;
 	execlist->pending_slot = NULL;
-	execlist->running_context = execlist->running_context ?
+	execlist->running_context = execlist->running_slot ?
 		&execlist->running_slot->ctx[0] : NULL;
 
 	gvt_dbg_el("[after] running slot %d/context %x pending slot %d\n",
Signature · 1 line
2.43.0
#1 lore raw

✗ LGCI.VerificationFailed: failure for drm/i915/gvt: Fix NULL pointer dereference in slot switch

== Series Details ==

== Series Details ==

Series: drm/i915/gvt: Fix NULL pointer dereference in slot switch
URL : https://patchwork.freedesktop.org/series/178498/
State : failure

== Summary ==

Series author address '[email protected]' is not on the allowlist, which prevents CI from being automatically triggered. If you want CI to run for this series, ask Patchwork project owners to click 'retest' on the series in Patchwork. Exception occurred during validation, bailing out!
Build URL: http://gfx-ci.igk.intel.com:8080/job/CI_PW_kernel/193109/ (on built-in)

reviewer
#2 lore raw
In reply to Tuo Li
Quoted 11 lines · Tuo Li

The running slot is updated to the pending slot before updating the running context. However, the condition checks the old running context instead of the newly assigned running slot.

When no pending slot exists, running_slot becomes NULL. If the previous running_context is non-NULL, the code attempts to access running_slot->ctx[0], resulting in a NULL pointer dereference.

To fix this possible NULL pointer dereference, check running_slot instead to ensure that running_context is updated only when a valid slot is available.

Well, just AI generated static check but without any runtime analysis, again...and can't even show kernel oops of this, as it simply can't happen..

Quoted 12 lines
Fixes 8453d674ae7e ("drm/i915/gvt: vGPU execlist virtualization")
---
 drivers/gpu/drm/i915/gvt/execlist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/gvt/execlist.c +0 -0
index 29147a9f162e..763c310f2aaf 100644

drivers/gpu/drm/i915/gvt/execlist.c static void switch_virtual_execlist_slot(struct intel_vgpu_execlist *execlist) · line 78

Quoted 7 lines
drivers/gpu/drm/i915/gvt/execlist.c +1 -1
@@ -73,7 +73,7 @@ static void switch_virtual_execlist_slot(struct intel_vgpu_execlist *execlist)
 
 	execlist->running_slot = execlist->pending_slot;
 	execlist->pending_slot = NULL;
-	execlist->running_context = execlist->running_context ?
+	execlist->running_context = execlist->running_slot ?
 		&execlist->running_slot->ctx[0] : NULL;
 

Current code calls this switch in case whenever running_slot is available, so it won't have null ptr reference. But code looks a little weird, as current code tried to assign running_context in other place e.g when new request happened, or even it might seem to miss when enter execlist idle state...but it is still valid in switch call. So I think this is just harmless. If you'd like for further cleanup, that needs testing result for sure.

Thanks.

author
#3 lore raw
Quoted 30 lines · Zhenyu Wang
Quoted 11 lines · Tuo Li

The running slot is updated to the pending slot before updating the running context. However, the condition checks the old running context instead of the newly assigned running slot.

When no pending slot exists, running_slot becomes NULL. If the previous running_context is non-NULL, the code attempts to access running_slot->ctx[0], resulting in a NULL pointer dereference.

To fix this possible NULL pointer dereference, check running_slot instead to ensure that running_context is updated only when a valid slot is available.

Well, just AI generated static check but without any runtime analysis, again...and can't even show kernel oops of this, as it simply can't happen..

Quoted 13 lines
Fixes 8453d674ae7e ("drm/i915/gvt: vGPU execlist virtualization")
---
 drivers/gpu/drm/i915/gvt/execlist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/gvt/execlist.c +0 -0
index 29147a9f162e..763c310f2aaf 100644
@@ -73,7 +73,7 @@ static void switch_virtual_execlist_slot(struct intel_vgpu_execlist *execlist)
 
Quoted 14 lines

drivers/gpu/drm/i915/gvt/execlist.c static void switch_virtual_execlist_slot(struct intel_vgpu_execlist *execlist) · line 78

Quoted 6 lines
drivers/gpu/drm/i915/gvt/execlist.c +1 -1
      execlist->running_slot = execlist->pending_slot;
      execlist->pending_slot = NULL;
-     execlist->running_context = execlist->running_context ?
+     execlist->running_context = execlist->running_slot ?
              &execlist->running_slot->ctx[0] : NULL;
 

Current code calls this switch in case whenever running_slot is available, so it won't have null ptr reference. But code looks a little weird, as current code tried to assign running_context in other place e.g when new request happened, or even it might seem to miss when enter execlist idle state...but it is still valid in switch call. So I think this is just harmless. If you'd like for further cleanup, that needs testing result for sure.

Thanks for the clarification. I will drop this patch. Sorry for the noise.

Sincerely,
Tuo Li