ARM: DMA-Mapping: add a new attribute to clear buffer
Subsystems (2)
RFC 1/1 ARM: DMA-Mapping: add a new attribute to clear buffer
From: Inki Dae <[email protected]>
This patch adds a new attribute, DMA_ATTR_SKIP_BUFFER_CLEAR to skip buffer clearing. The buffer clearing also flushes CPU cache so this operation has performance deterioration a little bit.
With this patch, allocated buffer region is cleared as default. So if you want to skip the buffer clearing, just set this attribute.
But this flag should be used carefully because this use might get access to some vulnerable content such as security data. So with this patch, we make sure that all pages will be somehow cleared before exposing to userspace.
For example, let's say that the security data had been stored in some memory and freed without clearing it.
And then malicious process allocated the region though some buffer allocator such as gem and ion without clearing it, and requested blit operation with cleared another buffer though gpu or other drivers. At this time, the malicious process could access the security data.
--- arch/arm/mm/dma-mapping.c | 6 ++++-- include/linux/dma-attrs.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)
arch/arm/mm/dma-mapping.c +4 -2
@@ -1058,7 +1058,8 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size,if (!page) goto error; -__dma_clear_buffer (page, size); +if (!dma_get_attr (DMA_ATTR_SKIP_BUFFER_CLEAR , attrs)) +__dma_clear_buffer (page, size);for (i =0 ; i < count; i++) pages[i] = page + i;
@@ -1082,7 +1083,8 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, pages[i + j] = pages[i] + j; } -__dma_clear_buffer (pages[i],PAGE_SIZE << order); +if (!dma_get_attr (DMA_ATTR_SKIP_BUFFER_CLEAR , attrs)) +__dma_clear_buffer (pages[i],PAGE_SIZE << order); i +=1 << order; count -=1 << order; }
include/linux/dma-attrs.h +1 -0
@@ -18,6 +18,7 @@ enum dma_attr {DMA_ATTR_NO_KERNEL_MAPPING ,DMA_ATTR_SKIP_CPU_SYNC ,DMA_ATTR_FORCE_CONTIGUOUS , +DMA_ATTR_SKIP_BUFFER_CLEAR , DMA_ATTR_MAX, };
Signature · 7 lines
1.7.4.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 14 lines · On Thursday 27 December 2012 05:00 PM, [email protected] wrote:
From: Inki Dae <[email protected]>
This patch adds a new attribute,
DMA_ATTR_SKIP_BUFFER_CLEARto skip buffer clearing. The buffer clearing also flushes CPU cache so this operation has performance deterioration a little bit.With this patch, allocated buffer region is cleared as default. So if you want to skip the buffer clearing, just set this attribute.
But this flag should be used carefully because this use might get access to some vulnerable content such as security data. So with this patch, we make sure that all pages will be somehow cleared before exposing to userspace.
Quoted 6 lines
For example, let's say that the security data had been stored in some memory and freed without clearing it.
And then malicious process allocated the region though some buffer allocator such as gem and ion without clearing it, and requested blit operation with cleared another buffer though gpu or other drivers. At this time, the malicious process could access the security data.
Isnt it always good to use such security related buffers through TZ rather than trying to guard them in the non-secure zone?
Quoted 37 lines
Signed-off-by Inki Dae <[email protected]>Signed-off-by Kyungmin Park <[email protected]>--- arch/arm/mm/dma-mapping.c | 6 ++++-- include/linux/dma-attrs.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)arch/arm/mm/dma-mapping.c +4
-2@@ -1058,7 +1058,8 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size,if (!page) goto error; -__dma_clear_buffer (page, size); +if (!dma_get_attr (DMA_ATTR_SKIP_BUFFER_CLEAR , attrs)) +__dma_clear_buffer (page, size);for (i =0 ; i < count; i++) pages[i] = page + i;@@ -1082,7 +1083,8 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, pages[i + j] = pages[i] + j; } -__dma_clear_buffer (pages[i],PAGE_SIZE << order); +if (!dma_get_attr (DMA_ATTR_SKIP_BUFFER_CLEAR , attrs)) +__dma_clear_buffer (pages[i],PAGE_SIZE << order); i +=1 << order; count -=1 << order; }include/linux/dma-attrs.h +0
-0
include/linux/dma-attrs.h enum dma_attr { · line 22
Quoted 5 lines
include/linux/dma-attrs.h +1
-0@@ -18,6 +18,7 @@ enum dma_attr {DMA_ATTR_NO_KERNEL_MAPPING ,DMA_ATTR_SKIP_CPU_SYNC ,DMA_ATTR_FORCE_CONTIGUOUS , +DMA_ATTR_SKIP_BUFFER_CLEAR , DMA_ATTR_MAX,
How is this new macro different from SKIP_CPU_SYNC?
include/linux/dma-attrs.h enum dma_attr { · line 24
Quoted 3 lines
include/linux/dma-attrs.h +0
-0};
Regards,
Subash
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
2013/1/1 Subash Patel <[email protected]>:
Quoted 26 lines · On Thursday 27 December 2012 05:00 PM, [email protected] wrote:
Quoted 15 lines
From: Inki Dae <[email protected]>
This patch adds a new attribute,
DMA_ATTR_SKIP_BUFFER_CLEARto skip buffer clearing. The buffer clearing also flushes CPU cache so this operation has performance deterioration a little bit.With this patch, allocated buffer region is cleared as default. So if you want to skip the buffer clearing, just set this attribute.
But this flag should be used carefully because this use might get access to some vulnerable content such as security data. So with this patch, we make sure that all pages will be somehow cleared before exposing to userspace.
Quoted 6 lines
For example, let's say that the security data had been stored in some memory and freed without clearing it.
And then malicious process allocated the region though some buffer allocator such as gem and ion without clearing it, and requested blit operation with cleared another buffer though gpu or other drivers. At this time, the malicious process could access the security data.
Quoted 3 lines
Isnt it always good to use such security related buffers through TZ rather than trying to guard them in the non-secure zone?
This is for normal world. We should consider security issue to normal world and also all cases as possible.
Quoted 40 lines
Quoted 40 lines
Signed-off-by Inki Dae <[email protected]>Signed-off-by Kyungmin Park <[email protected]>--- arch/arm/mm/dma-mapping.c | 6 ++++-- include/linux/dma-attrs.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)arch/arm/mm/dma-mapping.c +2
-1@@ -1058,7 +1058,8 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, if (!page) goto error; -__dma_clear_buffer (page, size); +if (!dma_get_attr (DMA_ATTR_SKIP_BUFFER_CLEAR , attrs)) +__dma_clear_buffer (page, size);for (i =0 ; i < count; i++)pages[i] = page + i;arch/arm/mm/dma-mapping.c +2
-1@@ -1082,7 +1083,8 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, pages[i + j] = pages[i] + j; } -__dma_clear_buffer (pages[i],PAGE_SIZE << order); +if (!dma_get_attr (DMA_ATTR_SKIP_BUFFER_CLEAR , attrs)) +__dma_clear_buffer (pages[i],PAGE_SIZE << order); i +=1 << order; count -=1 << order;}include/linux/dma-attrs.h +0
-0@@ -18,6 +18,7 @@ enum dma_attr {
Quoted 9 lines
include/linux/dma-attrs.h enum dma_attr { · line 22
Quoted 5 lines
include/linux/dma-attrs.h +1
-0DMA_ATTR_NO_KERNEL_MAPPING ,DMA_ATTR_SKIP_CPU_SYNC ,DMA_ATTR_FORCE_CONTIGUOUS , +DMA_ATTR_SKIP_BUFFER_CLEAR , DMA_ATTR_MAX,How is this new macro different from
SKIP_CPU_SYNC?
The purpose of this patch is to skip buffer clearing, not to skip cache opeation.
Quoted 6 lines
include/linux/dma-attrs.h enum dma_attr { · line 24
Quoted 3 lines
include/linux/dma-attrs.h +0
-0};Regards,
Subash
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>