[PATCH] dma-direct: zero out DMA_ATTR_NO_KERNEL_MAPPING buf

Hillf Danton hdanton at sina.com
Fri Sep 4 11:25:49 EDT 2020


The DMA buffer allocated is always cleared in DMA core and this is
making DMA_ATTR_NO_KERNEL_MAPPING non-special.

Fixes: d98849aff879 ("dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code")
Cc: Kees Cook <keescook at chromium.org>
Cc: Matthew Wilcox <willy at infradead.org>
Cc: Marek Szyprowski <m.szyprowski at samsung.com>
Cc: James Bottomley <James.Bottomley at HansenPartnership.com>
Signed-off-by: Hillf Danton <hdanton at sina.com>
---

--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -178,9 +178,17 @@ void *dma_direct_alloc_pages(struct devi
 
 	if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
 	    !force_dma_unencrypted(dev)) {
+		int i;
+
 		/* remove any dirty cache lines on the kernel alias */
 		if (!PageHighMem(page))
 			arch_dma_prep_coherent(page, size);
+
+		for (i = 0; i < size/PAGE_SIZE; i++) {
+			ret = kmap_atomic(page + i);
+			memset(ret, 0, PAGE_SIZE);
+			kunmap_atomic(ret);
+		}
 		/* return the page pointer as the opaque cookie */
 		ret = page;
 		goto done;
--




More information about the Linux-nvme mailing list