🇰🇷 한글 설명
Linux 커널의 PCI/sysfs 구성 요소에서 pci_write_legacy_io() 함수가 사용자 공간에서 입력한 바이트 수와 관계없이 항상 4바이트를 읽어 발생하는 경계 외 읽기(Out-of-bounds read) 취약점입니다. 이로 인해 할당된 메모리 범위를 벗어난 데이터를 읽게 되어 KASAN에서 slab-out-of-bounds 오류가 보고될 수 있습니다.
💡 쉬운 설명
컴퓨터가 데이터를 저장할 때 정해진 크기보다 더 많은 양을 읽으려다 보니, 허용되지 않은 메모리 영역을 엿볼 수 있는 보안 결함입니다. 이는 시스템의 안정성을 해치거나 민감한 정보가 노출될 위험이 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
PCI/sysfs: Fix out-of-bounds read in pci_write_legacy_io()
pci_write_legacy_io() loads 4 bytes from the kernfs write buffer
regardless of how many bytes userspace wrote:
if (count != 1 && count != 2 && count != 4)
return -EINVAL;
return pci_legacy_write(bus, off, *(u32 *)buf, count);
kernfs_fop_write_iter() allocates the buffer with kmalloc(len + 1),
so a 1-byte write to the legacy_io sysfs file allocates 2 bytes and
the unconditional u32 load reads up to 2 bytes past the end of the
allocation, which KASAN reports as a slab-out-of-bounds read.
Similarly, a 2-byte write overreads by 1 byte.
Thus, read only the number of bytes requested using get_unaligned_le16()
and get_unaligned_le32() for the 2 and 4 byte cases, interpreting the
buffer as little-endian to match the byte ordering of PCI I/O port
space.
The PowerPC implementation previously compensated for the generic
code's native-endian 32-bit load by shifting the value into place
for the 1 and 2 byte cases. The shifts were only correct on
big-endian kernels.
On little-endian PowerPC (POWER8 and later), they extracted the wrong
bytes, so a 1-byte write wrote an out-of-bounds byte instead of the
requested value. On big-endian, the native load also caused out_le16()
and out_le32() to reverse the user's bytes on the wire for 2 and 4 byte
writes. The little-endian helpers resolve both issues, so the shifts
are removed.
No changes are needed for the Alpha platform.
The legacy_io file is root-only and exists only on Alpha and PowerPC,
the two architectures that define HAVE_PCI_LEGACY.
📍 영향받는 시스템
PCI 레거시 기능을 사용하는 Alpha 및 PowerPC 아키텍처 기반의 Linux 커널
⚔️ 공격 벡터
루트 권한을 가진 사용자가 sysfs의 legacy_io 파일을 통해 특정 크기의 데이터를 작성하여 메모리 경계 외 읽기를 유도
🛡️ 대응 방법
get_unaligned_le16() 및 get_unaligned_le32()를 사용하여 요청된 바이트만큼만 읽도록 커널을 업데이트
🔧 검증 코드
커널 버전과 PCI 관련 설정 활성화 여부를 확인하여 해당 아키텍처 및 기능 사용 여부를 판단합니다.
uname -a && grep -i 'PCI' /proc/config.gz 2>/dev/null || grep -i 'PCI' /boot/config-$(uname -r)