🇰🇷 한글 설명
Linux 커널의 BPF 타이머 구현에서 bpf_timer_cancel_and_free와 bpf_timer_cancel 함수 간의 경쟁 상태(Race Condition)로 인해 Use-After-Free(UAF) 취약점이 발생합니다. 이 문제는 타이머 객체가 해제된 후에도 해당 메모리에 접근을 시도하여 시스템 불안정성이나 권한 상승을 초래할 수 있습니다.
💡 쉬운 설명
두 개의 작업이 동시에 타이머를 삭제하려고 할 때, 이미 삭제되어 사라진 메모리 공간을 다시 사용하려고 시도하는 오류입니다. 이로 인해 컴퓨터 시스템이 갑자기 멈추거나 해커가 시스템 제어권을 얻을 위험이 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
bpf: Fix racing between bpf_timer_cancel_and_free and bpf_timer_cancel
The following race is possible between bpf_timer_cancel_and_free
and bpf_timer_cancel. It will lead a UAF on the timer->timer.
bpf_timer_cancel();
spin_lock();
t = timer->time;
spin_unlock();
bpf_timer_cancel_and_free();
spin_lock();
t = timer->timer;
timer->timer = NULL;
spin_unlock();
hrtimer_cancel(&t->timer);
kfree(t);
/* UAF on t */
hrtimer_cancel(&t->timer);
In bpf_timer_cancel_and_free, this patch frees the timer->timer
after a rcu grace period. This requires a rcu_head addition
to the "struct bpf_hrtimer". Another kfree(t) happens in bpf_timer_init,
this does not need a kfree_rcu because it is still under the
spin_lock and timer->timer has not been visible by others yet.
In bpf_timer_cancel, rcu_read_lock() is added because this helper
can be used in a non rcu critical section context (e.g. from
a sleepable bpf prog). Other timer->timer usages in helpers.c
have been audited, bpf_timer_cancel() is the only place where
timer->timer is used outside of the spin_lock.
Another solution considered is to mark a t->flag in bpf_timer_cancel
and clear it after hrtimer_cancel() is done. In bpf_timer_cancel_and_free,
it busy waits for the flag to be cleared before kfree(t). This patch
goes with a straight forward solution and frees timer->timer after
a rcu grace period.
📍 영향받는 시스템
Linux Kernel (BPF 타이머 기능이 활성화된 버전)
⚔️ 공격 벡터
특수하게 조작된 BPF 프로그램을 실행하여 타이머 취소 함수 간의 경쟁 상태를 유도
🛡️ 대응 방법
Linux 커널을 최신 보안 패치가 적용된 버전으로 업데이트
🔧 검증 코드
출력된 커널 버전이 해당 취약점이 해결된 패치 버전 이후인지 확인