🇰🇷 한글 설명
리눅스 커널의 HID appletb-kbd 드라이버에서 비활성화 타이머 정리 경로 중 슬래시 사용 후 자유(UAF) 취약점이 발견되었습니다. 타이머 삭제 및 장치 참조 해제 순서가 잘못되어 동시 실행 시 해제된 메모리에 접근할 수 있는 두 가지竞합 조건이 존재합니다.
💡 쉬운 설명
시스템 종료 또는 드라이버 제거 과정에서 타이머와 메모리 해제 순서가 맞지 않아, 이미 사라진 메모리를 접근하려는 오류가 발생합니다. 이는 시스템 불안정이나 권한 상승을 유발할 수 있는 심각한 결함입니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
HID: appletb-kbd: fix UAF in inactivity-timer cleanup path
Commit 38224c472a03 ("HID: appletb-kbd: fix slab use-after-free bug in
appletb_kbd_probe") added timer_delete_sync(&kbd->inactivity_timer) to
both the probe close_hw error path and appletb_kbd_remove(), but the
way it was wired in left the inactivity timer reachable during driver
tear-down via two distinct windows.
Window A -- put_device() before timer_delete_sync():
put_device(&kbd->backlight_dev->dev);
timer_delete_sync(&kbd->inactivity_timer);
The inactivity_timer softirq reads kbd->backlight_dev and calls
backlight_device_set_brightness() -> mutex_lock(&ops_lock). If a
concurrent hid_appletb_bl unbind drops the last devm reference
between these two calls, the backlight_device is freed and the
mutex_lock() touches freed memory.
Window B -- backlight cleanup before hid_hw_stop():
if (kbd->backlight_dev) {
timer_delete_sync(...);
put_device(...);
}
hid_hw_close(hdev);
hid_hw_stop(hdev);
Even after Window A is closed, hid_hw_close()/hid_hw_stop() still run
afterwards, so a late ".event" callback from the HID core (USB URB
completion on real Apple hardware) can arrive after
timer_delete_sync() drained the softirq but before put_device() drops
the reference. That callback reaches reset_inactivity_timer(), which
calls mod_timer() and re-arms the timer. The freshly re-armed timer
can then fire on the about-to-be-freed backlight_device.
Both windows produce the same KASAN slab-use-after-free:
BUG: KASAN: slab-use-after-free in __mutex_lock+0x1aab/0x21c0
Read of size 8 at addr ffff88803ee9a108 by task swapper/0/0
Call Trace:
<IRQ>
__mutex_lock
backlight_device_set_brightness
appletb_inactivity_timer
call_timer_fn
run_timer_softirq
handle_softirqs
Allocated by task N:
devm_backlight_device_register
appletb_bl_probe
Freed by task M:
(concurrent hid_appletb_bl unbind path)
Close both windows at once by reworking the tear-down in
appletb_kbd_remove() and in the probe close_hw error path so that
1) hid_hw_close()/hid_hw_stop() run before the backlight cleanup,
guaranteeing no further .event callback can fire and re-arm the
timer, and
2) inside the "if (kbd->backlight_dev)" block, timer_delete_sync()
runs before put_device(), so the softirq is drained before the
final reference is dropped.
📍 영향받는 시스템
Linux kernel (HID appletb-kbd 모듈)
⚔️ 공격 벡터
동시 실행되는 HID 이벤트 콜백과 드라이어 제거 프로세스 간의 타이밍 경합을 통해 메모리 손상 유발
🛡️ 대응 방법
커널 패치 적용: appletb_kbd_remove 및 probe 오류 경로에서 hid_hw_stop()을 백라이트 정리 전에 실행하고, 타이머 삭제를 put_device() 전에 수행하도록 순서 수정
🔧 검증 코드
출력된 커널 버전이 패치가 적용된 최신 버전인지 확인하거나, dmesg에서 관련 UAF 오류 로그가 발생하지 않는지 확인