🇰🇷 한글 설명
Linux 커널의 arm64 아키텍처에서 cpu_switch_to() 및 call_on_irq_stack() 함수가 스택을 전환하는 동안 인터럽트(SErrors, Debug Exceptions, Pseudo-NMI 등)를 차단하지 못해 발생하는 취약점입니다. 이로 인해 Shadow Call Stack(SCS) 포인터가 잘못 저장되어 스택 데이터가 손상되고, 결과적으로 커널 패닉이 발생할 수 있습니다.
💡 쉬운 설명
컴퓨터가 작업 공간(스택)을 옮기는 아주 짧은 순간에 갑작스러운 방해(인터럽트)가 들어오면, 작업 기록이 엉뚱한 곳에 저장되어 시스템이 멈추는 문제입니다. 특히 특정 보안 기능이 켜져 있을 때 이 현상이 발생하여 시스템 안정성을 해칠 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
arm64/entry: Mask DAIF in cpu_switch_to(), call_on_irq_stack()
`cpu_switch_to()` and `call_on_irq_stack()` manipulate SP to change
to different stacks along with the Shadow Call Stack if it is enabled.
Those two stack changes cannot be done atomically and both functions
can be interrupted by SErrors or Debug Exceptions which, though unlikely,
is very much broken : if interrupted, we can end up with mismatched stacks
and Shadow Call Stack leading to clobbered stacks.
In `cpu_switch_to()`, it can happen when SP_EL0 points to the new task,
but x18 stills points to the old task's SCS. When the interrupt handler
tries to save the task's SCS pointer, it will save the old task
SCS pointer (x18) into the new task struct (pointed to by SP_EL0),
clobbering it.
In `call_on_irq_stack()`, it can happen when switching from the task stack
to the IRQ stack and when switching back. In both cases, we can be
interrupted when the SCS pointer points to the IRQ SCS, but SP points to
the task stack. The nested interrupt handler pushes its return addresses
on the IRQ SCS. It then detects that SP points to the task stack,
calls `call_on_irq_stack()` and clobbers the task SCS pointer with
the IRQ SCS pointer, which it will also use !
This leads to tasks returning to addresses on the wrong SCS,
or even on the IRQ SCS, triggering kernel panics via CONFIG_VMAP_STACK
or FPAC if enabled.
This is possible on a default config, but unlikely.
However, when enabling CONFIG_ARM64_PSEUDO_NMI, DAIF is unmasked and
instead the GIC is responsible for filtering what interrupts the CPU
should receive based on priority.
Given the goal of emulating NMIs, pseudo-NMIs can be received by the CPU
even in `cpu_switch_to()` and `call_on_irq_stack()`, possibly *very*
frequently depending on the system configuration and workload, leading
to unpredictable kernel panics.
Completely mask DAIF in `cpu_switch_to()` and restore it when returning.
Do the same in `call_on_irq_stack()`, but restore and mask around
the branch.
Mask DAIF even if CONFIG_SHADOW_CALL_STACK is not enabled for consistency
of behaviour between all configurations.
Introduce and use an assembly macro for saving and masking DAIF,
as the existing one saves but only masks IF.
📍 영향받는 시스템
Linux kernel (arm64 architecture)
⚔️ 공격 벡터
시스템의 특정 인터럽트(Pseudo-NMI 등)를 유발하여 스택 전환 과정 중의 레이스 컨디션을 이용한 서비스 거부(DoS)
🛡️ 대응 방법
Linux 커널을 최신 보안 패치가 적용된 버전으로 업데이트하여 DAIF 마스킹 로직을 적용해야 합니다.
🔧 검증 코드
출력된 커널 버전이 해당 취약점이 해결된 패치 버전 이후인지 확인합니다.