drm/amdgpu: add rcu_barrier() in module exit to prevent use-after-free
Subsystems (2)
PATCH 1/1 drm/amdgpu: add rcu_barrier() in module exit to prevent use-after-free
commit 9c85025c7ac2 ("drm/amdgpu: nuke amdgpu_userq_fence_slab v2") removed the dedicated slab for userq fences along with the rcu_barrier() call that was in amdgpu_userq_fence_slab_fini(). However, the amdgpu module still registers RCU callbacks via call_rcu() in amdgpu_userq_fence_release() and amdgpu_fence_release(). Without rcu_barrier(), pending RCU callbacks can reference freed module text after the module is unloaded, causing a page fault in rcu_do_batch():
BUG: unable to handle page fault for address: ffffffffc115e910 RIP: 0010:0xffffffffc115e910 Call Trace: <IRQ> rcu_do_batch+0x1c4/0x7f0 rcu_core+0x14d/0x330 handle_softirqs+0xd0/0x2b0
Add rcu_barrier() to amdgpu_exit() to ensure all pending RCU callbacks have completed before the module code pages are freed.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -3193,6 +3193,7 @@ static void __exit amdgpu_exit(void)amdgpu_unregister_atpx_handler ();amdgpu_acpi_release ();amdgpu_sync_fini (); +rcu_barrier ();mmu_notifier_synchronize ();amdgpu_xcp_drv_release (); }
Signature · 1 line
2.43.0
Christian König
maintainerQuoted 16 lines · Chengjun Yao
commit
9c85025c7ac2("drm/amdgpu: nukeamdgpu_userq_fence_slabv2") removed the dedicated slab for userq fences along with thercu_barrier()call that was inamdgpu_userq_fence_slab_fini(). However, the amdgpu module still registers RCU callbacks viacall_rcu()inamdgpu_userq_fence_release()andamdgpu_fence_release(). Withoutrcu_barrier(), pending RCU callbacks can reference freed module text after the module is unloaded, causing a page fault inrcu_do_batch():BUG: unable to handle page fault for address: ffffffffc115e910 RIP: 0010:0xffffffffc115e910 Call Trace: <IRQ> rcu_do_batch+0x1c4/0x7f0 rcu_core+0x14d/0x330 handle_softirqs+0xd0/0x2b0
Quoted 2 lines
Add
rcu_barrier()toamdgpu_exit()to ensure all pending RCU callbacks have completed before the module code pages are freed.
That is just papering over the fact that we don't support module unload with our amd-staging-drm-next tree in the first place.
The fence code can crash even with that RCU barrier at the moment.
The patches to allow this are still not back merged from upstream since they went into the Linux kernel through a different path.
Regards,
Christian.
Quoted 19 lines
Fixes 9c85025c7ac2 ("drm/amdgpu: nuke amdgpu_userq_fence_slab v2")Signed-off-by Chengjun Yao <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + 1 file changed, 1 insertion(+)drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0@@ -3193,6 +3193,7 @@ static void __exit amdgpu_exit(void)amdgpu_unregister_atpx_handler ();amdgpu_acpi_release ();amdgpu_sync_fini (); +rcu_barrier ();mmu_notifier_synchronize ();amdgpu_xcp_drv_release (); }