🇰🇷 한글 설명
Linux 커널의 slub 할당자에서 krealloc() 및 kvrealloc() 함수 사용 시 데이터 손실과 버퍼 오버플로가 발생하는 취약점입니다. NUMA 노드 이동 시 초기화되지 않은 크기 값으로 인해 데이터가 유실되거나, 객체 크기를 줄이는 과정에서 이전 크기만큼 데이터를 복사하여 메모리 경계를 넘어서는 쓰기 작업이 발생할 수 있습니다.
💡 쉬운 설명
메모리 크기를 조절하는 과정에서 컴퓨터가 실수로 데이터를 잘못 복사하거나, 정해진 공간보다 더 많은 데이터를 써버리는 오류입니다. 이로 인해 중요한 데이터가 사라지거나 시스템이 불안정해질 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
slub: fix data loss and overflow in krealloc()
Commit 2cd8231796b5 ("mm/slub: allow to set node and align in
k[v]realloc") introduced the ability to force a reallocation if the
original object does not satisfy new alignment or NUMA node, even when
the object is being shrunk.
This introduced two bugs in the reallocation fallback path:
1. Data loss during NUMA migration: The jump to 'alloc_new' happens
before 'ks' and 'orig_size' are initialized. As a result, the
memcpy() in the 'alloc_new' block would copy 0 bytes into the new
allocation.
2. Buffer overflow during shrinking: When shrinking an object while
forcing a new alignment, 'new_size' is smaller than the old size.
However, the memcpy() used the old size ('orig_size ?: ks'), leading
to an out-of-bounds write.
The same overflow bug exists in the kvrealloc() fallback path, where the
old bucket size ksize(p) is copied into the new buffer without being
bounded by the new size.
A simple reproducer:
// e.g. add to lkdtm as KREALLOC_SHRINK_OVERFLOW
while (1) {
void *p = kmalloc(128, GFP_KERNEL);
p = krealloc_node_align(p, 64, 256, GFP_KERNEL, NUMA_NO_NODE);
kfree(p);
}
demonstrates the issue:
==================================================================
BUG: KFENCE: out-of-bounds write in memcpy_orig+0x68/0x130
Out-of-bounds write at 0xffff8883ad757038 (120B right of kfence-#47):
memcpy_orig+0x68/0x130
krealloc_node_align_noprof+0x1c8/0x340
lkdtm_KREALLOC_SHRINK_OVERFLOW+0x8c/0xc0 [lkdtm]
lkdtm_do_action+0x3a/0x60 [lkdtm]
...
kfence-#47: 0xffff8883ad756fc0-0xffff8883ad756fff, size=64, cache=kmalloc-64
allocated by task 316 on cpu 7 at 97.680481s (0.021813s ago):
krealloc_node_align_noprof+0x19c/0x340
lkdtm_KREALLOC_SHRINK_OVERFLOW+0x8c/0xc0 [lkdtm]
lkdtm_do_action+0x3a/0x60 [lkdtm]
...
==================================================================
Fix it by moving the old size calculation to the top of __do_krealloc()
and bounding all copy lengths by the new allocation size.
📍 영향받는 시스템
Linux kernel (slub allocator를 사용하는 버전)
⚔️ 공격 벡터
커널 메모리 재할당(krealloc/kvrealloc)을 유도하여 메모리 오버플로를 일으키는 로컬 공격
🛡️ 대응 방법
커널 패치(Commit 2cd8231796b 관련 수정 사항)를 적용하여 재할당 시 크기 계산 및 복사 범위를 제한해야 함
🔧 검증 코드
현재 실행 중인 커널 버전을 확인하여 해당 취약점이 수정된 패치 버전인지 확인합니다.