🇰🇷 한글 설명
Linux 커널의 RISC-V 아키텍처에서 BPF JIT 실행 메모리 주소를 처리하는 patch_map() 로직의 결함이 수정되었습니다. CONFIG_STRICT_MODULE_RWX가 비활성화된 경우 BPF 텍스트 영역이 읽기 전용임에도 직접 쓰기를 시도하여 page fault와 -EFAULT가 발생하고, 그 결과 BPF 프로그램이 JIT 컴파일되지 못했습니다. 수정은 CONFIG_EXECMEM을 기준으로 임시 쓰기 가능 alias를 생성하도록 변경하는 것입니다.
💡 쉬운 설명
리눅스 커널이 RISC-V 장치에서 BPF 프로그램을 실행용 기계어로 바꿀 때 잘못된 메모리 쓰기 방식을 사용해 실패할 수 있었습니다. 이번 수정으로 BPF 프로그램이 정상적으로 컴파일되어 실행되도록 고쳐졌습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
riscv: patch: fix handling of bpf-jit execmem addresses
Commit 8718e5a3090b ("riscv: patch: skip fixmap mapping when kernel text
is already writable") gated the core_kernel_text() branch of patch_map()
on CONFIG_STRICT_KERNEL_RWX, and explicitly left the vmalloc branch
unchanged. That branch has a separate problem.
That branch only creates a temporary writable fixmap alias when
CONFIG_STRICT_MODULE_RWX is enabled, and otherwise assumes the target is
directly writable and returns the address unchanged. That assumption no
longer holds: bpf_prog_pack_alloc calls set_memory_rox() on every pack
unconditionally in alloc_new_pack(), independently of any
CONFIG_STRICT_*_RWX option, so BPF text in the vmalloc area is read-only
regardless of what CONFIG_STRICT_MODULE_RWX says.
With CONFIG_STRICT_MODULE_RWX=n, patch_map() returns the read-only
address directly, the subsequent copy_to_kernel_nofault() takes a
page fault and returns -EFAULT. bpf_arch_text_copy() turns that into
-EINVAL, which propagates through bpf_jit_binary_pack_finalize() to the
WARN_ON() in bpf_int_jit_compile() and leaves the program un-JITed.
Note that BPF cannot be fixed the way kprobes was in
commit bdc46e507b59 ("riscv: mm: make EXECMEM_KPROBES writable without
CONFIG_STRICT_MODULE_RWX"). EXECMEM_BPF is already PAGE_KERNEL, i.e.
writable at allocation time; the read-only mapping is established
afterwards by generic code in alloc_new_pack(), which arch code cannot
influence. The only place this can be handled is patch_map().
This is the same problem that was fixed on arm64 by commit b1480ed230ac
("arm64: patching: fix handling of execmem addresses"), and the fix is
the same: CONFIG_EXECMEM is what actually tracks whether the vmalloc
area can hold executable memory that needs a temporary alias to be
written. CONFIG_BPF_JIT, CONFIG_KPROBES and CONFIG_MODULES all select
it.
Note that this is not limited to CONFIG_MODULES=n. Unlike arm64, riscv
selects CONFIG_ARCH_OPTIONAL_KERNEL_RWX, so CONFIG_STRICT_MODULE_RWX can
be disabled with CONFIG_MODULES=y as well, and the bug is reachable in
that configuration too.
The !CONFIG_MMU build is unaffected: it has its own __patch_insn_set()
and __patch_insn_write() implementations and never calls patch_map().
📍 영향받는 시스템
CONFIG_STRICT_MODULE_RWX가 비활성화된 RISC-V 기반 Linux 커널 (패치 적용 이전 버전)
⚔️ 공격 벡터
명시된 정보로는 공격 벡터가 확인되지 않으며, 주로 BPF 프로그램 JIT 컴파일 실패를 일으키는 기능 결함(안정성) 문제입니다.
🛡️ 대응 방법
해당 커널 수정 커밋이 포함된 최신 Linux 커널 버전 또는 배포판 보안 업데이트로 업그레이드하십시오.
🔧 검증 코드
출력된 커널 버전을 배포판의 보안 권고나 커널 변경 로그와 대조하여 수정 커밋이 포함된 버전인지 확인하고, 필요 시 zcat /proc/config.gz 2>/dev/null | grep -E 'CONFIG_STRICT_MODULE_RWX|CONFIG_EXECMEM'로 설정을 점검합니다.