🇰🇷 한글 설명
Linux 커널의 PM hibernate 기능에서, 하이버네이션 복원 시 장치 probe 대기 로직(wait_for_device_probe)이 snapshot_open 단계에서 호출되어 misc_mtx 뮤텍스를 쥔 채 무한정 대기하는 AB-BA 교착 상태가 발생할 수 있었습니다. 패치는 해당 대기를 snapshot_write 및 snapshot_ioctl 단계로 지연시켜 문제를 완화합니다.
💡 쉬운 설명
컴퓨터가 절전 상태에서 깨어날 때 일부 장치 초기화를 기다리다가 여러 작업이 서로 멈춰버릴 수 있는 문제입니다. 수정으로 대기 시점을 늦춰 이런 멈춤 가능성을 줄였습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
PM: hibernate: defer device probing when resuming from hibernation
syzbot is reporting hung task at misc_open() [1], for there is a race
window of AB-BA deadlock which involves probe_count variable. Currently
wait_for_device_probe() from snapshot_open() from misc_open() can sleep
forever with misc_mtx held if probe_count cannot become 0.
When a device is probed by hub_event() work function, probe_count is
incremented before the probe function starts, and probe_count is
decremented after the probe function completed.
There are three cases that can prevent probe_count from dropping to 0.
(a) A device being probed stopped responding (i.e. broken/malicious
hardware).
(b) A process emulating a USB device using /dev/raw-gadget interface
stopped responding for some reason.
(c) New device probe requests keeps coming in before existing device
probe requests complete.
The phenomenon syzbot is reporting is (b). A process which is holding
system_transition_mutex and misc_mtx is waiting for probe_count to become
0 inside wait_for_device_probe(), but the probe function which is called
from hub_event() work function is waiting for the processes which are
blocked at mutex_lock(&misc_mtx) to respond via /dev/raw-gadget interface.
This patch mitigates (b) by deferring wait_for_device_probe() from
snapshot_open() to snapshot_write() and snapshot_ioctl(). Please note that
the possibility of (b) remains as long as any thread which is emulating a
USB device via /dev/raw-gadget interface can be blocked by uninterruptible
blocking operations (e.g. mutex_lock()).
Please also note that (a) and (c) are not addressed. Regarding (c), we
should change the code to wait for only one device which contains the
image for resuming from hibernation. I don't know how to address (a), for
use of timeout for wait_for_device_probe() might result in loss of user
data in the image. Maybe we should require the userland to wait for the
image device before opening /dev/snapshot interface.
📍 영향받는 시스템
Linux 커널 (해당 패치 적용 이전의 버전, 하이버네이션 기능 사용 시스템)
⚔️ 공격 벡터
로컬 사용자가 /dev/raw-gadget 등으로 USB 장치를 에뮬레이션하며 응답을 멈추게 하여 커널 작업을 교착 상태로 만드는 방식 (서비스 거부)
🛡️ 대응 방법
커널을 CVE-2022-50202 수정 패치가 포함된 최신 안정 버전으로 업데이트
🔧 검증 코드
출력된 커널 버전을 배포판 보안 공지 또는 해당 수정이 포함된 커널 버전과 비교해 패치 적용 여부를 확인합니다. 배포판 패키지 changelog에서 CVE-2022-50202 언급 여부도 함께 확인할 수 있습니다.