🇰🇷 한글 설명
Linux 커널의 usbfs에서 usbdev_release() 함수가 완료된 비동기 URB 목록을 비우기 전에 usb_device 참조를 먼저 해제하여 발생하는 Use-After-Free 취약점입니다. 장치 연결 해제 후 특정 조건에서 이미 해제된 메모리 영역을 참조하게 되어 시스템 충돌이나 권한 상승을 유발할 수 있습니다.
💡 쉬운 설명
USB 장치를 사용하는 프로그램이 장치를 뽑았을 때, 컴퓨터가 이미 삭제된 메모리 정보를 다시 읽으려고 시도하면서 발생하는 오류입니다. 이 과정에서 시스템이 멈추거나 해커가 시스템 제어권을 얻을 위험이 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
usb: usbfs: fix use-after-free of usb_device in usbdev_release()
usbdev_release() drops its reference to the struct usb_device before
draining the list of completed async URBs, but that drain path reads back
through the same object: free_async() calls dec_usb_memory_use_count()
for any URB whose buffer came from the usbfs mmap() region, and its first
statement is bus_to_hcd(ps->dev->bus).
After a disconnect the usbfs reference can be the last one, in which case
usb_put_dev() frees the device and the subsequent loop reads offset 80 of
freed memory and uses the result as a struct usb_hcd *, which
hcd_buffer_free_pages() then dereferences.
This is reachable by an unprivileged process that has read/write access to
a /dev/bus/usb node: mmap() the fd, submit one URB with a buffer inside the
mapping, wait for the device to be unplugged, then munmap() and close().
It reproduces on every attempt rather than being a race, because a live
MAP_SHARED vma holds a reference on the struct file, so usbdev_release()
cannot run until the last vma is gone and the freeing branch of
dec_usb_memory_use_count() is always taken.
BUG: KASAN: slab-use-after-free in dec_usb_memory_use_count+0x3ae/0x410
Read of size 8 at addr ffff8880122ee050 by task poc/769
CPU: 1 UID: 1000 PID: 769 Comm: poc Tainted: G B 6.12.94 #3
Call Trace:
dec_usb_memory_use_count+0x3ae/0x410
free_async+0x2aa/0x4f0
usbdev_release+0x375/0x460
__fput+0x3ea/0xb50
__x64_sys_close+0x86/0x100
Allocated by task 11:
usb_alloc_dev+0x55/0xd90
hub_event+0x2524/0x43d0
Freed by task 769:
kfree+0x121/0x360
device_release+0xd2/0x280
usb_put_dev+0x23/0x30
usbdev_release+0x2d8/0x460
Release the device reference after the drain loop instead. Nothing between
the two points requires it to have been dropped.
📍 영향받는 시스템
Linux kernel (usb: usbfs 관련 모듈이 포함된 버전)
⚔️ 공격 벡터
/dev/bus/usb 노드에 읽기/쓰기 권한이 있는 비특권 사용자가 mmap()과 URB 제출 후 장치 연결 해제를 유도하여 공격
🛡️ 대응 방법
usbdev_release() 함수에서 장치 참조 해제 시점을 drain loop 이후로 변경한 최신 커널 패치 적용
🔧 검증 코드
출력된 커널 버전이 해당 취약점이 수정된 패치 버전 이상인지 확인