🇰🇷 한글 설명
Linux 커널의 amba-pl011 시리얼 드라이버에서 원자적 컨텍스트(atomic context) 내에 잠자기(sleep)가 가능한 함수를 호출하여 발생하는 취약점입니다. PREEMPT_RT 커널 환경에서 클록을 활성화하는 과정 중 스핀락 경합이 발생하면 시스템이 충돌(BUG)할 수 있습니다.
💡 쉬운 설명
컴퓨터의 핵심 작업 중에는 잠시 멈추거나 기다리는 동작을 하면 안 되는데, 특정 장치(시리얼 포트)가 작동하는 과정에서 실수로 기다리는 동작을 시도하여 시스템이 멈추는 문제입니다. 이로 인해 시스템이 갑자기 중단되거나 오류가 발생할 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
serial: amba-pl011: keep console clock enabled for atomic writes
pl011_console_write_atomic() runs from nbcon atomic context, where
sleeping is not allowed. It calls clk_enable(), which takes the common-clk
enable_lock. Under PREEMPT_RT that is a sleeping lock:
clk_enable_lock() first tries spin_trylock_irqsave(), but on contention
falls back to spin_lock_irqsave(). Therefore, an atomic-context printk on
an RT kernel with a clk-backed pl011 can trip:
BUG: sleeping function called from invalid context at spinlock_rt.c:48
__might_resched from rt_spin_lock
rt_spin_lock from clk_enable_lock
clk_enable_lock from clk_enable
clk_enable from pl011_console_write_atomic
... from vprintk_emit
This was found and reproduced on PREEMPT_RT. Arm32 and arm64 DT SoCs are
affected; arm64 SBSA/ACPI has no clk, so clk_enable(NULL) short-circuits
before the lock. In addition, write_atomic() may be invoked from NMI
context and is documented to avoid locking. Removing clk_enable() from
the callback also avoids a potentially unsafe NMI acquisition of the
common-clock enable_lock.
An nbcon atomic-capable console must be printable from any context, so
the clock cannot be gated between writes. Enable the clock while the
console is available for output: use clk_prepare_enable() in
pl011_console_setup(), release it via clk_disable_unprepare() in the
console .exit() callback, and drop the per-write clk_enable()/clk_disable()
pairs from write_atomic() and write_thread().
When printk suspends consoles, drop the reference after
uart_suspend_port() stops console access and restore it before
uart_resume_port() -- but only if suspend actually marked the port
suspended (a wake-capable tty stays running and must keep its clock), and
keep it when console_suspend_enabled is false so no_console_suspend works.
The active power cost of keeping the clock enabled is platform-dependent:
none where the UART clock is a fixed always-on oscillator, real where it
is a gateable clock branch, which then cannot be gated (nor possibly can
its parent clocks) while the console is available for output. When serial
core actually suspends the port, the reference is released so the clock
provider can gate the clock tree.
📍 영향받는 시스템
PREEMPT_RT 커널이 적용된 Arm32 및 Arm64 DT 기반 SoC 시스템
⚔️ 공격 벡터
로컬 공격자가 시스템의 원자적 컨텍스트 내에서 특정 입출력을 유도하여 커널 패닉을 발생시킴
🛡️ 대응 방법
Linux 커널을 최신 패치가 적용된 버전으로 업데이트하여 clk_enable() 호출 방식을 수정해야 함
🔧 검증 코드
출력 결과에 PREEMPT_RT가 포함되어 있다면 해당 커널 환경에서 취약점이 발생할 가능성이 있는 시스템입니다.
uname -a | grep -E 'PREEMPT_RT'