Skip to content

mtd: rawnand: protect DMA engines from vmalloc'd buffers

ping.li linux-mtd lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest0 of 3 patches 0 repliesNew

Patches in v1 No applies recorded yet

None of the 3 patches the cover letter announces are in this archive.

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/3] mtd: rawnand: protect DMA engines from vmalloc'd buffers

From: Ping Li <[email protected]>

While discussing a proposal to also allocate the mtdchar read/write bounce buffers with kvmalloc() [1], an audit showed that three raw NAND controllers 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()).

The exposure predates that proposal: since the MEMREAD/MEMWRITE ioctls were converted to kvmalloc() (83208e106a8e8), a heavily fragmented system can already feed a vmalloc'd buffer into their dma_map_single() calls, which is not a valid input for non-linear-map addresses.

fsmc and intel 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 has an internal bounce buffer but only checks alignment; a virt_addr_valid() check extends it to cover non-linear-map buffers too.

These fixes are independent of the direction taken in [1].

[1] https://lore.kernel.org/linux-mtd/[email protected]/

Ping Li (3):
mtd: rawnand: fsmc: declare NAND_USES_DMA
mtd: rawnand: intel: declare NAND_USES_DMA
mtd: rawnand: r852: bounce non-linear-map buffers

 drivers/mtd/nand/raw/fsmc_nand.c             | 2 +-
 drivers/mtd/nand/raw/intel-nand-controller.c | 1 +
 drivers/mtd/nand/raw/r852.c                  | 4 ++--
 3 files changed, 4 insertions(+), 3 deletions(-)

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3 --
2.34.1