drm/qxl: zero-initialize struct qxl_release
Subsystems (4)
PATCH 1/1 drm/qxl: zero-initialize struct qxl_release
qxl_release_free() used to check release->base.ops to find out whether the embedded dma_fence had been initialized. Since commit 2bcbc706dfa0 ("dma-buf: add dma_fence_was_initialized function v2") it uses a flag in fence->flags instead, but qxl_release_alloc() allocates the release with kmalloc(), so the flags contain stale data.
Cursor releases never go through dma_fence_init(), so with a stale flag qxl_release_free() takes the initialized-fence path and calls dma_fence_signal() on a garbage fence->lock, triggering:
BUG: KASAN: slab-use-after-free in _raw_spin_lock_irqsave+0x7b/0xe0
Write of size 4 at addr ffff888010462700 by task kworker/3:1/91
CPU: 3 UID: 0 PID: 91 Comm: kworker/3:1
Not tainted 7.3.0-00341-gf47d223627f8-dirty #556 PREEMPT(lazy)
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
BIOS Arch Linux 1.17.0-2-2 04/01/2014
Workqueue: events qxl_gc_work
Call Trace:
<TASK>
dump_stack_lvl+0x4d/0x70
print_report+0x14b/0x4b0
? __pfx__raw_spin_lock_irqsave+0x10/0x10
kasan_report+0xfa/0x120
? _raw_spin_lock_irqsave+0x7b/0xe0
? _raw_spin_lock_irqsave+0x7b/0xe0
kasan_check_range+0x134/0x220
_raw_spin_lock_irqsave+0x7b/0xe0
? __pfx__raw_spin_lock_irqsave+0x10/0x10
? __kasan_slab_free+0x47/0x70
? kfree+0x21b/0x450
dma_fence_signal+0x72/0x130
qxl_release_free+0x2cf/0x600
qxl_garbage_collect+0x25c/0x500
? __pfx_qxl_garbage_collect+0x10/0x10
? __pfx__raw_spin_lock+0x10/0x10
process_one_work+0x696/0xf90
? __pfx___schedule+0x10/0x10
? __pfx_process_one_work+0x10/0x10
? _raw_spin_lock_irq+0x85/0xe0
? __pfx__raw_spin_lock_irq+0x10/0x10
worker_thread+0x4bd/0xd00
? __kthread_parkme+0x8d/0x170
? __pfx_worker_thread+0x10/0x10
? __pfx_worker_thread+0x10/0x10
kthread+0x32e/0x420
? recalc_sigpending+0x162/0x210
? __pfx_kthread+0x10/0x10
ret_from_fork+0x362/0x5a0
? __pfx_ret_from_fork+0x10/0x10
? __switch_to+0xaf9/0xf30
? __switch_to_asm+0x33/0x70
? __pfx_kthread+0x10/0x10
ret_from_fork_asm+0x1a/0x30
</TASK>Allocate with kzalloc() so an uninitialized fence is always seen as such.
--- drivers/gpu/drm/qxl/qxl_release.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/qxl/qxl_release.c +1 -1
@@ -91,7 +91,7 @@ qxl_release_alloc(struct qxl_device *qdev, int type,int handle;size_t size =sizeof (*release); - release =kmalloc (size,GFP_KERNEL ); + release =kzalloc (size,GFP_KERNEL );if (!release) {DRM_ERROR ("Out of memory\n" );return -ENOMEM ;
Signature · 1 line
2.56.1
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 15 lines
qxl_release_free()used to checkrelease->base.opsto find out whether the embeddeddma_fencehad been initialized. Since commit2bcbc706dfa0("dma-buf: adddma_fence_was_initializedfunction v2") it uses a flag infence->flagsinstead, butqxl_release_alloc()allocates the release withkmalloc(), so the flags contain stale data.Cursor releases never go through
dma_fence_init(), so with a stale flagqxl_release_free()takes the initialized-fence path and callsdma_fence_signal()on a garbagefence->lock, triggering:BUG: KASAN: slab-use-after-free in _raw_spin_lock_irqsave+0x7b/0xe0 Write of size 4 at addr ffff888010462700 by task kworker/3:1/91 CPU: 3 UID: 0 PID: 91 Comm: kworker/3:1 Not tainted 7.3.0-00341-gf47d223627f8-dirty #556 PREEMPT(lazy)
Quoted 6 lines
[ ... ]
Fixes 2bcbc706dfa0 ("dma-buf: add dma_fence_was_initialized function v2")Assisted-by claude-Sonnet 5.5Cc Christian König <[email protected]>Signed-off-by Óscar Megía López <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1