天下漏洞,尽知其名
HIGH

CVE-2026-18413 Zephyr ADC MCUX LPADC 缓冲区溢出漏洞

影响越界写入,可能造成内存破坏或提权

AI 研判

Zephyr RTOS 的 NXP MCUX LPADC 驱动未按 ADC API 约定校验采样目标缓冲区大小。当用户提供的 buffer_size 小于实际所需时,驱动仍按每通道每轮写入 16 位样本,导致缓冲区越界写入。该问题在中断与 DMA 路径均存在,在启用 CONFIG_USERSPACE 时可通过系统调用从用户态触发。

影响范围

Zephyr NXP MCUX LPADC 驱动

Zephyr RTOS 中 drivers/adc/adc_mcux_lpadc.c 的 NXP MCUX LPADC 驱动,具体受影响版本范围暂无公开信息。

漏洞详情

漏洞类型为缓冲区越界写入(CWE-787)。成因是 mcux_lpadc_start_read() 在将 sequence->buffer 赋给 data->buffer 前未检查 buffer_size,随后 mcux_lpadc_isr() 或 mcux_lpadc_dma_callback() 通过无界的 *data->buffer++ 逐样本写入。攻击者或调用方只需提交 buffer_size 过小的采样序列(如两通道仅给两字节缓冲区),第二个样本即写到缓冲区之外。

利用条件与风险

利用前提是能够调用 adc_read()/adc_read_async() 并控制采样序列的通道数与缓冲区大小;在 CONFIG_USERSPACE 构建下用户态线程即可触发,实战中可导致内存破坏,配合其他手段可能实现提权或拒绝服务。

修复建议

官方修复方案暂无公开信息;临时缓解措施为在驱动侧补充 buffer_size 校验,或在应用层确保采样缓冲区足够容纳所有启用通道的样本,并限制不可信调用方访问 ADC 系统调用。

原始情报

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.