🇰🇷 한글 설명
Linux 커널의 RISC-V 아키텍처에서 ZBB 최적화된 strnlen 함수가 경계 검사 전에 데이터를 미리 로드하여 발생하는 취약점입니다. 데이터 경계가 페이지 경계와 일치하고 다음 페이지가 매핑되지 않은 경우, 잘못된 메모리 접근으로 인해 시스템 오류(Fault)가 발생할 수 있습니다.
💡 쉬운 설명
컴퓨터가 글자 수를 셀 때, 정해진 범위를 넘어서 다음 데이터를 미리 읽으려다 발생하는 문제입니다. 이 과정에서 읽어서는 안 될 메모리 영역에 접근하면 시스템이 멈추거나 오류가 날 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
riscv: lib: Fix ZBB strnlen reading past count boundary
The ZBB-optimized strnlen loop loads one word ahead before checking the
aligned boundary:
REG_L t1, SZREG(t0) // load next word
addi t0, t0, SZREG // advance
orc.b t1, t1
bgeu t0, t4, 4f // boundary check AFTER load
where t4 = (s + count) & -SZREG. When s is aligned and count is a
multiple of SZREG, t4 equals s + count and the loop loads a full word
starting at exactly s + count. If s + count falls on a page boundary
with the next page unmapped, this faults.
Fix by computing the aligned boundary from the last valid byte
(s + count - 1) instead of s + count. This makes the loop stop at the
word containing the last valid byte rather than potentially loading the
word after it. The count == 0 case is already handled by the beqz
early exit.
Also add a pre-loop guard (bgeu t0, t4) for the case where all valid
bytes fit within the first word. With the adjusted boundary, t4 can
equal t0, and entering the loop with stale register state from the
first-word processing would produce incorrect results.
The final minu clamp ensures the result is still correct when the last
loaded word extends past s + count - 1 within the same aligned word.
📍 영향받는 시스템
ZBB 확장이 적용된 RISC-V 아키텍처 기반의 Linux 커널
⚔️ 공격 벡터
특정 조건(정렬된 주소 및 페이지 경계)을 가진 문자열 처리 시 메모리 접근 오류 유도
🛡️ 대응 방법
ZBB 최적화된 strnlen 루프의 경계 계산 로직을 수정하여 최신 커널로 업데이트
🔧 검증 코드
출력 결과에 riscv가 포함되어 있는지 확인하고, 사용 중인 커널 버전이 해당 취약점이 패치된 버전인지 확인합니다.
uname -a | grep -i 'riscv'