🇰🇷 한글 설명
Linux 커널의 hugetlb 메모리 관리에서 전역 페이지 할당 실패 시 subpool의 사용 카운터(used_hpages)가 제대로 복구되지 않는 버그입니다. 반복된 할당 실패로 인해 실제로 사용하지 않은 페이지도 계속 "사용 중"으로 표시되어 결국 subpool이 완전히 고갈되고 복구 불가능한 상태가 됩니다.
💡 쉬운 설명
메모리 할당이 실패해도 "사용 중" 카운트가 돌려받지 못해 누적되는 버그입니다. 반복되면 메모리 풀이 영구적으로 막혀서 더 이상 메모리를 할당받을 수 없게 됩니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
mm/hugetlb: restore failed global reservations to subpool
Commit a833a693a490 ("mm: hugetlb: fix incorrect fallback for subpool")
fixed an underflow error for hstate->resv_huge_pages caused by incorrectly
attributing globally requested pages to the subpool's reservation.
Unfortunately, this fix also introduced the opposite problem, which would
leave spool->used_hpages elevated if the globally requested pages could
not be acquired. This is because while a subpool's reserve pages only
accounts for what is requested and allocated from the subpool, its "used"
counter keeps track of what is consumed in total, both from the subpool
and globally. Thus, we need to adjust spool->used_hpages in the other
direction, and make sure that globally requested pages are uncharged from
the subpool's used counter.
Each failed allocation attempt increments the used_hpages counter by how
many pages were requested from the global pool. Ultimately, this renders
the subpool unusable, as used_hpages approaches the max limit.
The issue can be reproduced as follows:
1. Allocate 4 hugetlb pages
2. Create a hugetlb mount with max=4, min=2
3. Consume 2 pages globally
4. Request 3 pages from the subpool (2 from subpool + 1 from global)
4.1 hugepage_subpool_get_pages(spool, 3) succeeds.
used_hpages += 3
4.2 hugetlb_acct_memory(h, 1) fails: no global pages left
used_hpages -= 2
5. Subpool now has used_hpages = 1, despite not being able to
successfully allocate any hugepages. It believes it can now only
allocate 3 more hugepages, not 4.
With each failed allocation attempt incrementing the used counter, the
subpool eventually reaches a point where its used counter equals its
max counter. At that point, any future allocations that try to
allocate hugeTLB pages from the subpool will fail, despite the subpool
not having any of its hugeTLB pages consumed by any user.
Once this happens, there is no way to make the subpool usable again,
since there is no way to decrement the used counter as no process is
really consuming the hugeTLB pages.
The underflow issue that the original commit fixes still remains fixed
as well.
Without this fix, used_hpages would keep on leaking if
hugetlb_acct_memory() fails.
📍 영향받는 시스템
Linux kernel의 hugetlb 페이지 기능을 활성화한 모든 버전 (특히 고성능 데이터베이스, HPC, 가상화 환경)
⚔️ 공격 벡터
로컬 공격자가 hugetlb 서브풀에서 반복적으로 할당을 시도하여 실패시켜 카운터를 고갈하는 서비스 거부(DoS)
🛡️ 대응 방법
Linux 커널을 취약점 수정 버전 이상으로 업데이트하여 hugetlb 메모리 할당 로직 복구
🔧 검증 코드
커널 버전을 확인하고 현재 hugepages 상태(HugePages_Total, HugePages_Free, HugePages_Rsvd)를 조회하여 비정상적인 예약 카운트가 있는지 확인합니다.
cat /proc/version && cat /proc/meminfo | grep -i huge