🇰🇷 한글 설명
Linux 커널의 USB dummy-hcd 드라이버에서 USB 리셋과 드라이버 언바인드 간의 경쟁 조건(race condition)이 발생하여 NULL 포인터 참조로 인한 시스템 충돌을 야기할 수 있다. 이는 dum->callback_usage를 증가시키기 전에 stop_activity()를 호출할 때 발생하며, 다른 스레드가 dum->driver를 조기에 초기화할 수 있다.
💡 쉬운 설명
Linux 커널의 USB 드라이버에서 프로그램 종료와 USB 장치 재설정이 동시에 일어날 때 타이밍 문제로 시스템이 충돌할 수 있다. 로컬 사용자가 의도적으로 유발할 수 있는 중급 심각도의 결함이다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
USB: dummy-hcd: Fix locking/synchronization error
Syzbot testing was able to provoke an addressing exception and crash
in the usb_gadget_udc_reset() routine in
drivers/usb/gadgets/udc/core.c, resulting from the fact that the
routine was called with a second ("driver") argument of NULL. The bad
caller was set_link_state() in dummy_hcd.c, and the problem arose
because of a race between a USB reset and driver unbind.
These sorts of races were not supposed to be possible; commit
7dbd8f4cabd9 ("USB: dummy-hcd: Fix erroneous synchronization change"),
along with a few followup commits, was written specifically to prevent
them. As it turns out, there are (at least) two errors remaining in
the code. Another patch will address the second error; this one is
concerned with the first.
The error responsible for the syzbot crash occurred because the
stop_activity() routine will sometimes drop and then re-acquire the
dum->lock spinlock. A call to stop_activity() occurs in
set_link_state() when handling an emulated USB reset, after the test
of dum->ints_enabled and before the increment of dum->callback_usage.
This allowed another thread (doing a driver unbind) to sneak in and
grab the spinlock, and then clear dum->ints_enabled and dum->driver.
Normally this other thread would have to wait for dum->callback_usage
to go down to 0 before it would clear dum->driver, but in this case it
didn't have to wait since dum->callback_usage had not yet been
incremented.
The fix is to increment dum->callback_usage _before_ calling
stop_activity() instead of after. Then the thread doing the unbind
will not clear dum->driver until after the call to
usb_gadget_udc_reset() safely returns and dum->callback_usage has been
decremented again.
📍 영향받는 시스템
Linux kernel 5.10 이상의 dummy_hcd 포함 모든 배포판
⚔️ 공격 벡터
로컬 공격, USB 리셋과 드라이버 언바인드 동시 실행
🛡️ 대응 방법
패치가 적용된 최신 커널 버전으로 업데이트
🔧 검증 코드
현재 커널 버전 확인. 5.15 이상 또는 배포판의 최신 LTS 버전이면 일반적으로 패치가 적용되어 있다.