[PATCH v4 0/3] mtd: rawnand: protect DMA engines from vmalloc'd buffers
From: Ping Li
Date: Wed Nov 25 2026 - 06:51:25 EST
While discussing a proposal to also allocate the mtdchar read/write
bounce buffers with kvmalloc() [1], an audit showed that raw NAND
controllers may DMA the buffers handed by the NAND core without
declaring NAND_USES_DMA, so nand_base never bounces non-linear-map
buffers for them (see the use_bounce_buf logic in
nand_do_read_ops()/nand_do_write_ops()).
Non-linear-map buffers are not hypothetical: mtdblock's write cache
is vmalloc'ed and UBIFS passes vmalloc'ed LPT buffers to
mtd_write().
intel and r852 have no protection at all; declaring NAND_USES_DMA
lets nand_base bounce through chip->data_buf as the other
DMA-capable controllers (arasan, denali, meson, mtk, nuvoton...)
already do. r852 also advertises its 512-byte alignment
requirement through chip->buf_align, so misaligned linear buffers
are bounced by the core as well.
While at it, a leak in intel's ebu_dma_start() (mapping never
unmapped on success, wrong device used on the error path) found
during the audit is fixed as well.
Changes in v4 (following Miquel's review [2]):
- r852: advertise the 512-byte alignment requirement through
chip->buf_align instead of keeping a local justification; drop
the code comment.
Changes in v3 (following Miquel's review [3]):
- r852: use the core bounce through NAND_USES_DMA instead of
extending the local condition.
- Add Cc: stable to the three patches.
Changes in v2 (following the AI review of v1):
- Drop the fsmc patch: nothing has set host->mode since
a1b1e1d5bdfe ("mtd: nand: fsmc: finally remove
fsmc_nand_platform_data"), so the DMA paths are dead code and
fsmc_exec_op() always takes the PIO branch.
- Fix the Fixes: tags.
- Add a fix for the ebu_dma_start() unmap problems.
[1] https://lore.kernel.org/linux-mtd/20261119090055.1255028-1-ping.li@xxxxxxxxxxxx/
[2] https://lore.kernel.org/all/87o6bdz1fm.fsf@xxxxxxxxxxx/
[3] https://lore.kernel.org/all/875wxl1ea6.fsf@xxxxxxxxxxx/
Ping Li (3):
mtd: rawnand: intel: declare NAND_USES_DMA
mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start()
mtd: rawnand: r852: declare NAND_USES_DMA
drivers/mtd/nand/raw/intel-nand-controller.c | 8 +++++---
drivers/mtd/nand/raw/r852.c | 3 +++
2 files changed, 8 insertions(+), 3 deletions(-)
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
--
2.34.1