🇰🇷 한글 설명
Linux 커널의 ring-buffer에서 RB_FORCE_8BYTE_ALIGNMENT 설정이 활성화된 경우, 이벤트 길이를 계산할 때 데이터 길이를 잘못 보고하는 취약점이 발견되었습니다. 작은 크기의 이벤트에 대해 실제보다 4바이트 더 큰 데이터 길이를 반환하여 데이터 정렬 및 계산 오류를 유발할 수 있습니다.
💡 쉬운 설명
데이터를 저장하는 공간의 크기를 계산할 때, 특정 설정이 켜져 있으면 실제 데이터보다 4바이트 더 크게 잘못 계산되는 버그입니다. 이로 인해 데이터의 시작 위치나 크기가 어긋나 시스템 로그 등에 오류가 발생할 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
ring-buffer: Fix event length with forced 8-byte alignment
When RB_FORCE_8BYTE_ALIGNMENT is true, rb_calculate_event_length()
reserves the space of event->array[0] for placing the data length and
rb_update_event() stores the data length in event->array[0]
accordingly. As a result the whole event length will add extra 4 bytes
for sizeof(event.array[0]) unconditionally.
But ring_buffer_event_length() only subtracts the
sizeof(event->array[0]) for events larger than RB_MAX_SMALL_DATA +
sizeof(event->array[0]). As a result, small events on architectures
with RB_FORCE_8BYTE_ALIGNMENT=true report a data length that is 4
bytes larger than expected.
To fix it, add the RB_FORCE_8BYTE_ALIGNMENT as a condition to subtract
the size of that length field whenever RB_FORCE_8BYTE_ALIGNMENT is
true.
This issue is observed in a riscv64 kernel with
CONFIG_HAVE_64BIT_ALIGNED_ACCESS set to y, when we run ftrace selftest
trace_marker_raw.tc, we get the weird log: for cases where the id is
1..100, the number of data field is 8*N, but once id exceeds 100, the
number of data field becomes 8*N+4:
# 1 buf: 58 00 00 00 80 5e d1 63 (number of data field is 8*1)
...
# a buf: 58 ... (number of data field is 8*2)
...
# 64 buf: 58 ... (number of data field is 8*13)
# 65 buf: 58 ... (number of data field is 8*13+4)
After applying this change, the number of data field keeps being 8*N+4
consistently.
📍 영향받는 시스템
RB_FORCE_8BYTE_ALIGNMENT가 활성화된 Linux 커널 (특히 riscv64 아키텍처)
⚔️ 공격 벡터
직접적인 공격보다는 시스템 로그(ftrace) 데이터의 무결성 오류 및 데이터 해석 오류를 유발함
🛡️ 대응 방법
RB_FORCE_8BYTE_ALIGNMENT 조건에 따라 이벤트 길이를 올바르게 계산하도록 커널 패치를 적용해야 함
🔧 검증 코드
커널 버전과 CONFIG_HAVE_64BIT_ALIGNED_ACCESS 설정이 'y'로 되어 있는지 확인하여 취약 환경 여부를 판단합니다.
uname -a && grep -E 'CONFIG_HAVE_64BIT_ALIGNED_ACCESS' /boot/config-$(uname -r)