Skip to contentSkip to conversation

ARM: dma-mapping: don't allow DMA mappings to be marked executable

PATCH New Russell King - ARM Linux 2 participants 4 messages Oct 24, 2013 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: dma-mapping: don't allow DMA mappings to be marked executable

While looking at some features which Kees talked about on Tuesday, I discovered that our DMA mappings were incorrectly marked executable, which means that they can be subject to speculative instruction prefetches. This turns off executable permission for these mappings. I'm intending to push this for v3.12 as a fix.

8<====
From: Russell King <[email protected]>
ARM: dma-mapping: don't allow DMA mappings to be marked executable

DMA mapping permissions were being derived from pgprot_kernel directly without using PAGE_KERNEL. This causes them to be marked with executable permission, which is not what we want. Fix this.

---
 arch/arm/mm/dma-mapping.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/arm/mm/dma-mapping.c +2 -2
index 7f9b179..838e871 100644
@@ -688,7 +688,7 @@ static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
 void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
 		    gfp_t gfp, struct dma_attrs *attrs)
 {
-	pgprot_t prot = __get_dma_pgprot(attrs, pgprot_kernel);
+	pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL);
 	void *memory;
 
 	if (dma_alloc_from_coherent(dev, size, handle, &memory))
@@ -701,7 +701,7 @@ void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
 static void *arm_coherent_dma_alloc(struct device *dev, size_t size,
 	dma_addr_t *handle, gfp_t gfp, struct dma_attrs *attrs)
 {
-	pgprot_t prot = __get_dma_pgprot(attrs, pgprot_kernel);
+	pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL);
 	void *memory;
 
 	if (dma_alloc_from_coherent(dev, size, handle, &memory))
Signature · 1 line
1.7.4.4
#1 lore raw

PATCH 1/1 ARM: dma-mapping: don't allow DMA mappings to be marked executable

Hi Russell,

arch/arm/mm/dma-mapping.c static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, · line 691

Quoted 8 lines · Russell King - ARM Linux
arch/arm/mm/dma-mapping.c +1 -1
@@ -688,7 +688,7 @@ static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
 void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
 		    gfp_t gfp, struct dma_attrs *attrs)
 {
-	pgprot_t prot = __get_dma_pgprot(attrs, pgprot_kernel);
+	pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL);

I think we lose the shareability attribute we add to pgprot_kernel when SMP. So this creates a mismatched aliases and could have implications on the barrier use (though I think we use the full system DSB in most cases related to DMA). But architecturally I would feel better if we have the same shareability domain.

Signature · 1 line
Catalin
#2 lore raw

PATCH 1/1 ARM: dma-mapping: don't allow DMA mappings to be marked executable

Quoted 17 lines · Catalin Marinas

Hi Russell,

arch/arm/mm/dma-mapping.c static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, · line 691

Quoted 8 lines · Russell King - ARM Linux
arch/arm/mm/dma-mapping.c +1 -1
@@ -688,7 +688,7 @@ static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
 void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
 		    gfp_t gfp, struct dma_attrs *attrs)
 {
-	pgprot_t prot = __get_dma_pgprot(attrs, pgprot_kernel);
+	pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL);

I think we lose the shareability attribute we add to pgprot_kernel when SMP. So this creates a mismatched aliases and could have implications on the barrier use (though I think we use the full system DSB in most cases related to DMA). But architecturally I would feel better if we have the same shareability domain.

We don't.

#define _MOD_PROT(p, b) __pgprot(pgprot_val(p) | (b))

#define PAGE_KERNEL _MOD_PROT(pgprot_kernel, L_PTE_XN)
#define PAGE_KERNEL_EXEC pgprot_kernel

PAGE_KERNEL is used in generic code to setup kernel mappings by things like vmalloc() etc.

#3 lore raw

PATCH 1/1 ARM: dma-mapping: don't allow DMA mappings to be marked executable

Quoted 19 lines · Russell King - ARM Linux
Quoted 15 lines · Catalin Marinas

arch/arm/mm/dma-mapping.c static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, · line 691

Quoted 8 lines · Russell King - ARM Linux
arch/arm/mm/dma-mapping.c +1 -1
@@ -688,7 +688,7 @@ static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
 void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
 		    gfp_t gfp, struct dma_attrs *attrs)
 {
-	pgprot_t prot = __get_dma_pgprot(attrs, pgprot_kernel);
+	pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL);

I think we lose the shareability attribute we add to pgprot_kernel when SMP. So this creates a mismatched aliases and could have implications on the barrier use (though I think we use the full system DSB in most cases related to DMA). But architecturally I would feel better if we have the same shareability domain.

We don't.

Quoted 7 lines

#define _MOD_PROT(p, b) __pgprot(pgprot_val(p) | (b))

#define PAGE_KERNEL _MOD_PROT(pgprot_kernel, L_PTE_XN)
#define PAGE_KERNEL_EXEC pgprot_kernel

PAGE_KERNEL is used in generic code to setup kernel mappings by things like vmalloc() etc.

Ah, yes, it works correctly then.

Signature · 1 line
Catalin