🇰🇷 한글 설명
Linux 커널의 watch_queue_set_size()와 post_one_notification() 사이에 경쟁 조건이 존재합니다. 메모리 순서 보장이 없어 notes 포인터가 NULL인 상태에서 역참조될 수 있으며, 이로 인해 커널 NULL 포인터 역참조 및 패닉이 발생할 수 있습니다. 수정은 nr_notes를 smp_store_release()로 마지막에 게시하고 post_one_notification()에서 smp_load_acquire()로 읽도록 변경하는 것입니다.
💡 쉬운 설명
리눅스 커널에서 알림 큐를 설정하는 과정과 알림을 보내는 과정이 동시에 실행될 때 순서가 꼬여 잘못된 메모리를 읽을 수 있습니다. 이로 인해 시스템이 갑자기 멈추는 문제가 생길 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
watch_queue: Fix note pool publication race in watch_queue_set_size()
There is a race between watch_queue_set_size() and post_one_notification().
watch_queue_set_size() publishes wqueue->notes, notes_bitmap, nr_pages and
nr_notes with plain stores, and post_one_notification() reads them with
plain loads under a different lock, so nothing orders the four stores
against the poster's loads: depending on the build, notes can be stored
last (gcc 14 on x86-64 does this). Since keyctl_watch_key() lets a watch
attach to a queue before it is sized, post_one_notification() can already
be running on another CPU at that moment: it reads nr_notes > 0, passes
its bounds check, and then reads notes while it is still NULL,
dereferencing notes[0].
An unprivileged user triggers this reliably by watching one of its own
keys through a notification pipe and racing ioctl(IOC_WATCH_QUEUE_SET_SIZE)
on that pipe against keyctl(KEYCTL_SETPERM) on the key from another CPU,
triggering:
BUG: kernel NULL pointer dereference, address: 0000000000000000
RIP: 0010:post_one_notification.isra.0+0xa2/0x1e0
Call Trace:
__post_watch_notification+0x148/0x180
keyctl_setperm_key+0x119/0x130
do_syscall_64+0x108/0x4c0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Kernel panic - not syncing: Fatal exception in interrupt
Fix this by publishing nr_notes last with smp_store_release(), and by
reading it once with smp_load_acquire() in post_one_notification() before
the bitmap and the page array are touched. A poster that observes a
non-zero nr_notes then also observes the pool behind it; one that observes
zero drops the notification as before.
📍 영향받는 시스템
패치가 적용되지 않은 Linux 커널 (수정 커밋 이전 버전, 다중 CPU 환경의 watch_queue/keyctl 기능 사용 시스템)
⚔️ 공격 벡터
권한이 없는 로컬 사용자가 자신의 키를 알림 파이프로 감시하면서 한 CPU에서는 IOC_WATCH_QUEUE_SET_SIZE ioctl을, 다른 CPU에서는 KEYCTL_SETPERM을 동시에 호출하는 경쟁 상태를 유발하여 커널 패닉을 일으킵니다.
🛡️ 대응 방법
배포판 벤더가 제공하는 보안 업데이트 커널로 업그레이드하거나, 수정 커밋이 포함된 Linux 커널 버전으로 업데이트하고 재부팅합니다.
🔧 검증 코드
출력된 커널 버전을 배포판 보안 공지 또는 upstream 수정 커밋 포함 여부와 대조하여 패치 적용 여부를 판단하며, 해당 버전이 수정 이전이면 취약한 것으로 봅니다.