Skip to contentSkip to conversation

drm/vc4: Use managed KMS polling to fix UAF on unbind

PATCH Applied Karl Mehltretter 2 participants 2 messages Aug 22 – Sep 14

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/vc4: Use managed KMS polling to fix UAF on unbind

vc4_kms_load() calls drm_kms_helper_poll_init() but the driver provides no matching drm_kms_helper_poll_fini(). The output poll work stays scheduled after unbind and runs on the freed drm_device:

  # modprobe vc4; rmmod vc4; sleep 10
  BUG: KASAN: slab-use-after-free in delayed_work_timer_fn
  BUG: KASAN: slab-use-after-free in drm_client_dev_hotplug [drm]
  Workqueue: events output_poll_execute [drm_kms_helper]
  Allocated by task 171: __devm_drm_dev_alloc
  Freed by task 262 (rmmod): drm_dev_put / component_del

Use drmm_kms_helper_poll_init() so polling is finalized with the device, as other drivers do.

Fixes c8b75bca92cb ("drm/vc4: Add KMS support for Raspberry Pi.")
Assisted-by Claude:claude-fable-5

---
Tested on a Raspberry Pi 400 (BCM2711), v7.2-11658-g26260251022f, with

KASAN: report gone, rmmod/insmod loop clean.
 drivers/gpu/drm/vc4/vc4_kms.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_kms.c +1 -1
index b17e73bce384..82a7f2ac4c7e 100644
@@ -1188,7 +1188,7 @@ int vc4_kms_load(struct drm_device *dev)
 
 	drm_mode_config_reset(dev);
 
-	drm_kms_helper_poll_init(dev);
+	drmm_kms_helper_poll_init(dev);
 
 	return 0;
 }
Signature · 1 line
2.39.5 (Apple Git-154)
reviewer Applied
#1 lore raw
Quoted 4 lines · Karl Mehltretter

vc4_kms_load() calls drm_kms_helper_poll_init() but the driver provides no matching drm_kms_helper_poll_fini(). The output poll work stays scheduled after unbind and runs on the freed drm_device:

Quoted 8 lines
  # modprobe vc4; rmmod vc4; sleep 10
  BUG: KASAN: slab-use-after-free in delayed_work_timer_fn
  BUG: KASAN: slab-use-after-free in drm_client_dev_hotplug [drm]
  Workqueue: events output_poll_execute [drm_kms_helper]
  Allocated by task 171: __devm_drm_dev_alloc
  Freed by task 262 (rmmod): drm_dev_put / component_del

[...]

Applied, thanks!

[1/1] drm/vc4: Use managed KMS polling to fix UAF on unbind

      commit: 073a30d75f309812ed61af134f24ffef4107b13a

Best regards,
- Maíra