🇰🇷 한글 설명
Linux 커널의 damos_walk() 함수가 비활성 컨텍스트에서 오류 반환 시 ctx->walk_control을 초기화하지 않아 스택 메모리의 댕글링 포인터가 남습니다. 이로 인해 컨텍스트 재시작 시 use-after-free 또는 이후 호출에서 영구적인 -EBUSY 오류가 발생할 수 있습니다.
💡 쉬운 설명
Linux 커널의 메모리 관리 모듈에서 임시 변수의 포인터를 제대로 정리하지 않는 버그입니다. 이는 메모리 오류와 기능 오작동을 유발할 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
mm/damon/core: clear walk_control on inactive context in damos_walk()
damos_walk() sets ctx->walk_control to the caller-provided control
structure before checking whether the context is running. If the context
is inactive (damon_is_running() returns false), the function returns
-EINVAL without clearing ctx->walk_control. This leaves a dangling
pointer to a stack-allocated structure that will be freed when the caller
returns.
This is structurally identical to the bug fixed in commit f9132fbc2e83
("mm/damon/core: remove call_control in inactive contexts") for
damon_call(), which had the same pattern of linking a control object and
returning an error without unlinking it.
The dangling walk_control pointer can cause:
1. Use-after-free if the context is later started and kdamond
dereferences ctx->walk_control (e.g., in damos_walk_cancel()
which writes to control->canceled and calls complete())
2. Permanent -EBUSY from subsequent damos_walk() calls, since the
stale pointer is non-NULL
Nonetheless, the real user impact is quite restrictive. The
use-after-free is impossible because there is no damos_walk() callers who
starts the context later. The permanent -EBUSY can actually confuse
users, as DAMON is not running. But the symptom is kept only while the
context is turned off. Turning it on again will make DAMON internally
uses a newly generated damon_ctx object that doesn't have the invalid
damos_walk_control pointer, so everything will work fine again.
Fix this by clearing ctx->walk_control under walk_control_lock before
returning -EINVAL, mirroring the fix pattern from f9132fbc2e83.
📍 영향받는 시스템
Linux kernel mm/damon/core 모듈 (패치 이전 모든 버전)
⚔️ 공격 벡터
Local - inactive DAMON context에서 damos_walk() 호출 트리거 필요
🛡️ 대응 방법
Linux 커널 패치 적용 - walk_control_lock 하에서 ctx->walk_control 초기화 추가
🔧 검증 코드
커널 버전 확인 후 DAMON 모듈 활성화 여부 확인. DAMON이 활성화되어 있으면 패치 필요 여부 검토
uname -r && grep -q 'walk_control' /sys/kernel/debug/damon 2>/dev/null && echo 'DAMON enabled' || echo 'DAMON not available'