🇰🇷 한글 설명
NXP MCUX LPADC 드라이버가 ADC 시퀀스의 목적지 버퍼 크기를 검증하지 않아 발생하는 취약점입니다. 사용자 모드 스레드가 버퍼 크기보다 많은 샘플을 요청할 경우, 커널 모드에서 인접한 메모리 영역(커널 데이터, 스택 등)에 데이터를 덮어쓰는 메모리 오염이 발생할 수 있습니다.
💡 쉬운 설명
데이터를 담을 그릇보다 더 많은 데이터를 넣으라고 명령하여, 그릇 밖으로 넘친 데이터가 컴퓨터의 중요한 시스템 영역을 망가뜨리는 문제입니다. 이를 통해 해커가 시스템의 권한을 탈취하거나 컴퓨터를 멈추게 할 수 있습니다.
🇺🇸 원문 (English)
The ADC API requires each driver to reject a sampling sequence whose destination buffer is too small: the buffer_size field of struct adc_sequence in include/zephyr/drivers/adc.h documents that "the driver must ensure that samples are not written beyond the limit and it must return an error if the buffer turns out to be not large enough". The NXP MCUX LPADC driver did not honour that contract. mcux_lpadc_start_read() in drivers/adc/adc_mcux_lpadc.c performed no buffer-size check at all before assigning data->buffer = sequence->buffer. Each completed conversion then stores one 16-bit sample per enabled channel per sampling round through an unbounded *data->buffer++: in mcux_lpadc_isr() for interrupt-driven builds, and in mcux_lpadc_dma_callback() for DMA-driven builds on releases that have the DMA path. A sequence selecting two channels with a two-byte buffer, for example, has its second sample written past the end of the buffer.
On a build with CONFIG_USERSPACE, adc_read() and adc_read_async() are system calls. The handler in drivers/adc/adc_handlers.c copies the sequence in from user memory, verifies only that [buffer, buffer + buffer_size) is writable by the calling thread, and rejects a user-supplied options->callback; it deliberately leaves the size arithmetic to the driver. A user-mode thread that has been granted access to an LPADC device object therefore fully controls channels, buffer, buffer_size and options->extra_samplings, and can request far more samples than its buffer can hold: up to channels * 65536 samples into a two-byte buffer, since the sample pointer is only rewound on a repeat sampling, never on the extra samplings of a sequence.
The resulting stores are performed by the driver in kernel mode (in the ADC interrupt handler or the DMA completion callback), where the MPU does not restrict the thread's memory domain, so the write walks linearly out of the user partition and into adjacent memory such as other partitions, kernel data or thread stacks. The impact is kernel-memory corruption of attacker-chosen length at an attacker-chosen offset, a plausible privilege-escalation and denial-of-service primitive from an unprivileged user-mode thread. Builds without CONFIG_USERSPACE are affected only as a caller-side robustness defect, since the application itself supplies the buffer.
The fix calls the new shared helper adc_sequence_validate_buffer() in drivers/adc/adc_common.c from mcux_lpadc_start_read(). The helper computes active_channels sizeof(uint16_t) (1 + extra_samplings) and returns -ENOMEM before any sampling is started.
📍 영향받는 시스템
Zephyr OS 기반 NXP MCUX LPADC 드라이버를 사용하는 시스템 (CONFIG_USERSPACE 활성화 시 위험)
⚔️ 공격 벡터
권한이 낮은 사용자 모드 스레드가 버퍼 크기보다 큰 샘플링 시퀀스를 요청하여 커널 메모리 오염 유도
🛡️ 대응 방법
drivers/adc/adc_common.c에 추가된 adc_sequence_validate_buffer() 함수를 통해 버퍼 크기 검증 로직을 적용한 최신 드라이버로 업데이트
🔧 검증 코드
명령어 실행 결과 mcux_lpadc_start_read 함수 내에서 해당 검증 함수를 호출하고 있다면 취약점이 해결된 것입니다.
grep -r "adc_sequence_validate_buffer" drivers/adc/mcux_lpadc.c