🇰🇷 한글 설명
Linux 커널의 DAMON 구성 요소에서 damos_walk() 함수와 kdamond_fn() 종료 과정 사이에 레이스 컨디션(경쟁 상태)이 발생하여 데드락이 유발될 수 있는 취약점입니다. 서로 다른 뮤텍스로 보호되는 요청 등록과 컨텍스트 해제 과정이 충돌하면서, 요청이 처리되지 않은 채 스레드가 무한 대기 상태에 빠질 수 있습니다.
💡 쉬운 설명
시스템의 메모리 사용량을 분석하는 기능이 종료되는 순간에 새로운 분석 요청이 들어오면, 시스템이 응답하지 않고 멈춰버리는 현상이 발생할 수 있습니다. 이는 작업이 끝났는지 확인하는 절차와 새로운 작업을 추가하는 절차가 서로 맞물리지 않아 발생하는 문제입니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
mm/damon/core: fix damos_walk() vs kdamond_fn() exit race
When kdamond_fn() main loop is finished, the function cancels remaining
damos_walk() request and unset the damon_ctx->kdamond so that API callers
and API functions themselves can show the context is terminated.
damos_walk() adds the caller's request to the queue first. After that, it
shows if the kdamond of the damon_ctx is still running (damon_ctx->kdamond
is set). Only if the kdamond is running, damos_walk() starts waiting for
the kdamond's handling of the newly added request.
The damos_walk() requests registration and damon_ctx->kdamond unset are
protected by different mutexes, though. Hence, damos_walk() could race
with damon_ctx->kdamond unset, and result in deadlocks.
For example, let's suppose kdamond successfully finished the damow_walk()
request cancelling. Right after that, damos_walk() is called for the
context. It registers the new request, and shows the context is still
running, because damon_ctx->kdamond unset is not yet done. Hence the
damos_walk() caller starts waiting for the handling of the request.
However, the kdamond is already on the termination steps, so it never
handles the new request. As a result, the damos_walk() caller thread
infinitely waits.
Fix this by introducing another damon_ctx field, namely
walk_control_obsolete. It is protected by the
damon_ctx->walk_control_lock, which protects damos_walk() request
registration. Initialize (unset) it in kdamond_fn() before letting
damon_start() returns and set it just before the cancelling of the
remaining damos_walk() request is executed. damos_walk() reads the
obsolete field under the lock and avoids adding a new request.
After this change, only requests that are guaranteed to be handled or
cancelled are registered. Hence the after-registration DAMON context
termination check is no longer needed. Remove it together.
The issue is found by sashiko [1].
📍 영향받는 시스템
Linux Kernel (DAMON 모듈을 사용하는 버전)
⚔️ 공격 벡터
로컬 시스템에서 특정 API 호출을 통해 DAMON 컨텍스트 종료와 새로운 요청 등록을 동시에 유도하여 데드락 발생
🛡️ 대응 방법
Linux 커널을 최신 보안 패치가 적용된 버전으로 업데이트하여 walk_control_obsolete 필드를 통한 동기화 로직을 적용해야 합니다.
🔧 검증 코드
출력된 커널 버전을 확인하여 해당 취약점이 수정된 패치 버전 이상인지 확인합니다.