🇰🇷 한글 설명
Linux 커널의 KSM(Kernel Samepage Merging) 기능에서 scan_get_next_rmap_item 함수가 VMA 내의 모든 페이지 주소를 순회하면서 발생하는 성능 저하 문제입니다. 대규모 가상 메모리 영역에 매핑되지 않은 빈 공간(hole)이 많을 경우, ksmd가 불필요한 탐색을 수행하며 CPU 자원을 과도하게 점유하는 현상이 발생합니다.
💡 쉬운 설명
메모리 관리 프로그램이 실제 데이터가 없는 빈 공간까지 일일이 확인하느라 컴퓨터의 두뇌(CPU)를 100% 사용하며 느려지는 문제입니다. 패치를 통해 데이터가 있는 곳만 빠르게 건너뛰도록 개선되었습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
ksm: use range-walk function to jump over holes in scan_get_next_rmap_item
Currently, scan_get_next_rmap_item() walks every page address in a VMA to
locate mergeable pages. This becomes highly inefficient when scanning
large virtual memory areas that contain mostly unmapped regions, causing
ksmd to use large amount of cpu without deduplicating much pages.
This patch replaces the per-address lookup with a range walk using
walk_page_range(). The range walker allows KSM to skip over entire
unmapped holes in a VMA, avoiding unnecessary lookups. This problem was
previously discussed in [1].
Consider the following test program which creates a 32 TiB mapping in the
virtual address space but only populates a single page:
#include <unistd.h>
#include <stdio.h>
#include <sys/mman.h>
/* 32 TiB */
const size_t size = 32ul * 1024 * 1024 * 1024 * 1024;
int main() {
char *area = mmap(NULL, size, PROT_READ | PROT_WRITE,
MAP_NORESERVE | MAP_PRIVATE | MAP_ANON, -1, 0);
if (area == MAP_FAILED) {
perror("mmap() failed\n");
return -1;
}
/* Populate a single page such that we get an anon_vma. */
*area = 0;
/* Enable KSM. */
madvise(area, size, MADV_MERGEABLE);
pause();
return 0;
}
$ ./ksm-sparse &
$ echo 1 > /sys/kernel/mm/ksm/run
Without this patch ksmd uses 100% of the cpu for a long time (more then 1
hour in my test machine) scanning all the 32 TiB virtual address space
that contain only one mapped page. This makes ksmd essentially deadlocked
not able to deduplicate anything of value. With this patch ksmd walks
only the one mapped page and skips the rest of the 32 TiB virtual address
space, making the scan fast using little cpu.
📍 영향받는 시스템
Linux Kernel (KSM 기능이 활성화된 버전)
⚔️ 공격 벡터
매우 큰 가상 메모리 영역을 할당하고 일부만 데이터를 채운 뒤 KSM을 활성화하여 CPU 자원을 고갈시키는 DoS(서비스 거부) 공격
🛡️ 대응 방법
해당 취약점이 해결된 최신 Linux 커널 버전으로 업데이트
🔧 검증 코드
출력된 커널 버전이 해당 패치가 적용된 배포판의 보안 업데이트 버전인지 확인