🇰🇷 한글 설명
Linux 커널의 x86/SGX 드라이버에서, 메모리 오류(MCE)로 손상(poison)된 EPC 페이지가 여전히 재할당 대상 목록에 남아 회수(reclaim) 시도가 이루어질 수 있는 문제입니다. 이 경우 EWB 마이크로코드 연산 중 코어가 종료되어 커널 패닉이 발생할 수 있으므로, 손상된 페이지를 재회수 목록에서 제거하도록 수정되었습니다.
💡 쉬운 설명
메모리 하드웨어 오류가 난 보안 영역(SGX) 페이지를 시스템이 억지로 다시 쓰려다 CPU가 멈추고 시스템이 다운될 수 있는 결함입니다. 해당 페이지를 재사용 대상에서 빼도록 고쳐졌습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
x86/sgx: Prevent attempts to reclaim poisoned pages
TL;DR: SGX page reclaim touches the page to copy its contents to
secondary storage. SGX instructions do not gracefully handle machine
checks. Despite this, the existing SGX code will try to reclaim pages
that it _knows_ are poisoned. Avoid even trying to reclaim poisoned pages.
The longer story:
Pages used by an enclave only get epc_page->poison set in
arch_memory_failure() but they currently stay on sgx_active_page_list until
sgx_encl_release(), with the SGX_EPC_PAGE_RECLAIMER_TRACKED flag untouched.
epc_page->poison is not checked in the reclaimer logic meaning that, if other
conditions are met, an attempt will be made to reclaim an EPC page that was
poisoned. This is bad because 1. we don't want that page to end up added
to another enclave and 2. it is likely to cause one core to shut down
and the kernel to panic.
Specifically, reclaiming uses microcode operations including "EWB" which
accesses the EPC page contents to encrypt and write them out to non-SGX
memory. Those operations cannot handle MCEs in their accesses other than
by putting the executing core into a special shutdown state (affecting
both threads with HT.) The kernel will subsequently panic on the
remaining cores seeing the core didn't enter MCE handler(s) in time.
Call sgx_unmark_page_reclaimable() to remove the affected EPC page from
sgx_active_page_list on memory error to stop it being considered for
reclaiming.
Testing epc_page->poison in sgx_reclaim_pages() would also work but I assume
it's better to add code in the less likely paths.
The affected EPC page is not added to &node->sgx_poison_page_list until
later in sgx_encl_release()->sgx_free_epc_page() when it is EREMOVEd.
Membership on other lists doesn't change to avoid changing any of the
lists' semantics except for sgx_active_page_list. There's a "TBD" comment
in arch_memory_failure() about pre-emptive actions, the goal here is not
to address everything that it may imply.
This also doesn't completely close the time window when a memory error
notification will be fatal (for a not previously poisoned EPC page) --
the MCE can happen after sgx_reclaim_pages() has selected its candidates
or even *inside* a microcode operation (actually easy to trigger due to
the amount of time spent in them.)
The spinlock in sgx_unmark_page_reclaimable() is safe because
memory_failure() runs in process context and no spinlocks are held,
explicitly noted in a mm/memory-failure.c comment.
📍 영향받는 시스템
Linux 커널 SGX 지원 x86 시스템 (수정 이전 커널 버전, 배포판별 패치 상태 확인 필요)
⚔️ 공격 벡터
로컬 사용자 또는 SGX 엔클레이브 운영 환경에서 메모리 오류 발생 시 커널 패닉을 유발하는 서비스 거부(DoS) 형태이며, 공격자가 임의로 유발하기는 어려운 조건부 결함입니다.
🛡️ 대응 방법
배포판 제공 최신 커널 업데이트를 적용하여 해당 upstream 수정이 포함된 버전으로 재부팅합니다.
🔧 검증 코드
커널 버전이 배포판 보안 권고에서 이 CVE 수정이 포함된 버전 이상인지 비교하고, SGX 지원 여부와 디바이스 존재를 확인합니다. SGX가 없거나 디바이스가 없으면 이 취약점의 영향을 받지 않습니다.
uname -r && (grep -i sgx /proc/cpuinfo | head -1 || echo 'SGX 미지원') && (ls /dev/sgx_enclave /dev/sgx/enclave 2>/dev/null || echo 'SGX 디바이스 없음')