Issue #3490 has been reported by tuxillo.

----------------------------------------
Bug #3490: drm: unloading a TTM driver panics with "memory chunk is already 
free"
http://bugs.dragonflybsd.org/issues/3490

* Author: tuxillo
* Status: New
* Priority: Normal
* Target version: 6.6
* Start date: 2026-11-29
----------------------------------------
As of master 98c93bc104, kldunload of a TTM based drm driver panics. On a 
Radeon HD 5450, with nothing having opened the device, the first kldunload 
radeon gives:

<pre>
panic: memory chunk 0xfffff8026764f900 is already free!
chunk_mark_free() at chunk_mark_free+0xae
_kfree() at _kfree+0x2a2
drm_global_item_unref() at drm_global_item_unref+0x62
radeon_ttm_fini() at radeon_ttm_fini+0x10c
radeon_bo_fini() at radeon_bo_fini+0x11
</pre>

kobject_release() (sys/dev/drm/linux_kobject.c) calls ktype->release(), which 
usually frees the object the kobject is embedded in, and then reads kobj->name 
from that memory to free it. TTM embeds its kobjects at offset 0 
(ttm_mem_global, ttm_mem_zone) and the slab allocator reuses the first word of 
a freed chunk for its free list, so the "name" it frees is a free list link. 
This came in with 01537ba397, which added the kfree() of the name.

The attached patch takes the name before calling release and frees it 
afterwards, the order Linux's kobject_cleanup() uses.

TESTING: on master 64a78aecd3 (linux_kobject.c and the TTM unload path haven't 
changed since), on the Radeon, with drm.ko built before and after the patch and 
radeon loaded with nothing else using it. Before, the first kldunload radeon 
panicked as above. After, it completed with "[TTM] Zone kernel: Used memory at 
exit: 0 kiB" and the same for dma32. Loading radeon again then panicked in 
radeon_device_init(), a separate bug; with that fixed too, three 
kldunload/kldload cycles in a row completed.

---Files--------------------------------
0001-drm-fix-use-after-free-of-the-name-in-kobject_releas.patch (1.63 KB)


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://bugs.dragonflybsd.org/my/account

Reply via email to