🇰🇷 한글 설명
Linux 커널의 SPI i.MX 드라이버에서 DMA 바운스 버퍼가 실제 DMA 매핑 길이보다 작게 할당되어 슬랩 메모리 손상이 발생합니다. 이로 인해 할당 범위 밖의 메모리가 DMA API로 조작되며, 인접 객체의 참조 카운트 손상과 커널 패닉으로 이어질 수 있습니다. 해당 수정은 버퍼 할당과 동기화 길이를 캐시 라인 정렬 길이로 맞추는 것입니다.
💡 쉬운 설명
SPI 장치와 주고받는 데이터를 담는 메모리 공간이 실제 사용 범위보다 작게 잡혀 있어서, 옆에 있는 다른 데이터를 잘못 덮어쓰는 문제입니다. 그 결과 시스템이 멈추거나 재부팅될 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
spi: imx: fix slab corruption from undersized DMA bounce buffers
Since commit faa8e404ad8e ("spi: imx: support dynamic burst length for
ECSPI DMA mode"), the driver allocates its private DMA TX/RX buffers
with kzalloc(dma_len), where dma_len is only rounded up to 4 bytes, but
maps, syncs and unmaps them with DMA_CACHE_ALIGNED_LEN(dma_len), i.e.
rounded up to the cache line size. As a result, the DMA API operates on
memory beyond the end of the allocation.
This was observed on a custom i.MX8MP platform with an mcp251xfd CAN
controller under heavy RPMSG load, as a series of refcount_t warnings
triggered from rpmsg_recv_done() in virtio_rpmsg_bus:
refcount_t: addition on 0; use-after-free.
refcount_t: underflow; use-after-free.
refcount_t: saturated; leaking memory.
Leading finally to an "Unable to handle kernel paging request" oops.
Reproducing this problem took between 30 minutes and roughly 30 hours
under the same workload.
Hardware watchpoints on the refcount of a struct rpmsg_endpoint showed
it was overwritten from 2 to 1 by __pi_memcpy_generic() in the
irq/155-spi2.0 thread. Additionally it was found that a "normal"
rpmsg_recv_done() took 11µs +/-2µs from its kref_get to kref_put. In
the error case the same sequence took about 215µs +/-10µs. Based on
this, an LLM was used to identify the size mismatch fixed here.
Allocate the buffers with DMA_CACHE_ALIGNED_LEN(dma_len) so they cover
the full mapped length, and use the same length for
dma_sync_single_for_cpu() to stay consistent with map and unmap.
With this patch applied, the same workload ran for more than 200 hours
without the problem reproducing.
📍 영향받는 시스템
Linux 커널의 spi-imx 드라이버를 사용하는 i.MX 계열 SoC 기반 시스템(커밋 faa8e404ad8e 이후 버전)
⚔️ 공격 벡터
로컬 또는 주변 장치 트래픽 부하 상황에서 자연 발생하며, 조작된 SPI 전송 패턴이나 RPMSG 부하를 통해 서비스 거부 유발이 가능
🛡️ 대응 방법
Linux 커널을 해당 취약점을 수정한 최신 stable 버전으로 업데이트하거나 vendor 패치를 적용
🔧 검증 코드
커널 버전을 확인한 뒤 소스에 DMA_CACHE_ALIGNED_LEN이 버퍼 할당에 사용되면 패치가 반영된 것이고, 결과가 없거나 구버전이면 업데이트가 필요합니다.
uname -r && grep -n DMA_CACHE_ALIGNED_LEN drivers/spi/spi-imx.c 2>/dev/null