You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] RT-Thread serial v1: Reopening a device configured for INT_TX in DMA_TX mode causes the 4-byte tx_fifo to be treated as an rt_serial_tx_dma structure, resulting in out-of-bounds heap access and invalid function pointer calls. #12072
QEMU vexpress-a9 (bsp/qemu-vexpress-a9), UART via serial v1 with DMA_TX. Not board-specific
Develop Toolchain
Other
Describe the bug
Bug Description
In the serial v1 framework (components/drivers/serial/dev_serial.c), a vulnerability occurs when a device initially opened in interrupt transmission mode (RT_DEVICE_FLAG_INT_TX) is reopened in DMA transmission mode (RT_DEVICE_FLAG_DMA_TX).
The previously allocated 4-byte struct rt_serial_tx_fifo remains unchanged, but the DMA transmission path treats it as a 48-byte struct rt_serial_tx_dma. This results in out-of-bounds heap reads and writes.
rt_device_open() (components/drivers/core/device.c) invokes device_open again when the same device is opened with different flags. Since RT_DEVICE_OFLAG_MASK is 0xf0f, which includes both INT_TX (0x400) and DMA_TX (0x800), rt_serial_open() is called again even when only the transmission mode changes.
rt_serial_open() allocates a transmission object only when serial->serial_tx == RT_NULL (dev_serial.c:858). If an object has already been allocated, it simply enables RT_DEVICE_FLAG_DMA_TX in open_flag (line 902), leaving the existing rt_serial_tx_fifo unchanged.
The DMA transmission path subsequently casts serial->serial_tx to struct rt_serial_tx_dma * and accesses its data_queue member.
_serial_dma_tx() (lines 712, 714)
DMA completion handler (line 1657)
Close handler (line 991)
The data_queue member starts at offset 4, which is outside the bounds of the original 4-byte allocation.
Steps to Reproduce
Open a serial device that supports both INT_TX and DMA_TX using:
In the earlier commit 23c05e4, the same vulnerability caused execution to jump to a heap address through the queue->evt_notify function pointer, resulting in a crash.
Conditions Required
The UART driver must register both RT_DEVICE_FLAG_INT_TX and RT_DEVICE_FLAG_DMA_TX.
For example, bsp/stm32/drv_usart.c registers INT_TX | uart_dma_flag.
The reverse sequence is also problematic. If the device is first opened in DMA mode and then reopened in interrupt mode, the existing rt_serial_tx_dma object is incorrectly treated as an rt_serial_tx_fifo.
Activity
github-actions commentedon Nov 20, 2026
如需认领并处理此 Issue,请评论
/claim。To claim and work on this issue, comment
/claim.Finder16 commentedon Nov 20, 2026
/claim
github-actions commentedon Nov 20, 2026
@Finder16 has claimed this issue.
[drivers][serial] reject reopening a v1 serial device in a different …