Skip to contentSkip to conversation

arm: dma-mapping: fix off-by-one error in bitmap size check

PATCH Superseded Marek Szyprowski 3 participants 4 messages Jul 1, 2015 – Jul 2, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: dma-mapping: fix off-by-one error in bitmap size check

nr_bitmaps member of mapping structure stores the number of already allocated bitmaps and it is interpreted as loop iterator (it starts from 0 not from 1), so a comparison against number of possible bitmap extensions should include this fact. This patch fixes this by changing the extension failure condition. This issue has been introduced by commit 4d852ef8c2544ce21ae41414099a7504c61164a0 ("arm: dma-mapping: Add support to extend DMA IOMMU mappings").

CC stable at vger.kernel.org # v3.15+
---
 arch/arm/mm/dma-mapping.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mm/dma-mapping.c +1 -1
index a64b7f621067..05619542a1c0 100644
@@ -2015,7 +2015,7 @@ static int extend_iommu_mapping(struct dma_iommu_mapping *mapping)
 {
 	int next_bitmap;
 
-	if (mapping->nr_bitmaps > mapping->extensions)
+	if (mapping->nr_bitmaps => mapping->extensions)
 		return -EINVAL;
 
 	next_bitmap = mapping->nr_bitmaps;
Signature · 1 line
1.9.2
#1 lore raw

PATCH 1/1 arm: dma-mapping: fix off-by-one error in bitmap size check

Quoted 20 lines · Marek Szyprowski

nr_bitmaps member of mapping structure stores the number of already allocated bitmaps and it is interpreted as loop iterator (it starts from 0 not from 1), so a comparison against number of possible bitmap extensions should include this fact. This patch fixes this by changing the extension failure condition. This issue has been introduced by commit 4d852ef8c2544ce21ae41414099a7504c61164a0 ("arm: dma-mapping: Add support to extend DMA IOMMU mappings").

CC stable at vger.kernel.org # v3.15+
---
 arch/arm/mm/dma-mapping.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mm/dma-mapping.c +0 -0
index a64b7f621067..05619542a1c0 100644

arch/arm/mm/dma-mapping.c static int extend_iommu_mapping(struct dma_iommu_mapping *mapping) · line 2018

Quoted 5 lines
arch/arm/mm/dma-mapping.c +1 -1
@@ -2015,7 +2015,7 @@ static int extend_iommu_mapping(struct dma_iommu_mapping *mapping)
 {
        int next_bitmap;
 
-       if (mapping->nr_bitmaps > mapping->extensions)
+       if (mapping->nr_bitmaps => mapping->extensions)

Did you build test this?

Quoted 11 lines
arch/arm/mm/dma-mapping.c +0 -1
                return -EINVAL;
 
        next_bitmap = mapping->nr_bitmaps;
--

1.9.2

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#2 lore raw

PATCH v2 1/1 arm: dma-mapping: fix off-by-one error in bitmap size check

In reply to Marek Szyprowski

nr_bitmaps member of mapping structure stores the number of already allocated bitmaps and it is interpreted as loop iterator (it starts from 0 not from 1), so a comparison against number of possible bitmap extensions should include this fact. This patch fixes this by changing the extension failure condition. This issue has been introduced by commit 4d852ef8c2544ce21ae41414099a7504c61164a0 ("arm: dma-mapping: Add support to extend DMA IOMMU mappings").

CC stable at vger.kernel.org # v3.15+

---
V2 fixed build problem caused by a hurry in patch preparation. My fault. I'm really sorry for the noise.

Best regards
Marek Szyprowski, PhD
Samsung R&D Institute Poland

---
 arch/arm/mm/dma-mapping.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mm/dma-mapping.c +1 -1
index a64b7f621067..05619542a1c0 100644
@@ -2015,7 +2015,7 @@ static int extend_iommu_mapping(struct dma_iommu_mapping *mapping)
 {
 	int next_bitmap;
 
-	if (mapping->nr_bitmaps > mapping->extensions)
+	if (mapping->nr_bitmaps >= mapping->extensions)
 		return -EINVAL;
 
 	next_bitmap = mapping->nr_bitmaps;
Signature · 1 line
1.9.2
#3 lore raw

PATCH v2 1/1 arm: dma-mapping: fix off-by-one error in bitmap size check

Dear Marek,

Quoted 27 lines · On Wed, 01 Jul 2015 15:46:38 +0200 Marek Szyprowski <[email protected]>…

nr_bitmaps member of mapping structure stores the number of already allocated bitmaps and it is interpreted as loop iterator (it starts from 0 not from 1), so a comparison against number of possible bitmap extensions should include this fact. This patch fixes this by changing the extension failure condition. This issue has been introduced by commit 4d852ef8c2544ce21ae41414099a7504c61164a0 ("arm: dma-mapping:
Add support to extend DMA IOMMU mappings").

CC stable at vger.kernel.org # v3.15+

---
V2 fixed build problem caused by a hurry in patch preparation. My fault. I'm really sorry for the noise.

Best regards
Marek Szyprowski, PhD
Samsung R&D Institute Poland

---
 arch/arm/mm/dma-mapping.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mm/dma-mapping.c +0 -0
index a64b7f621067..05619542a1c0 100644

arch/arm/mm/dma-mapping.c static int extend_iommu_mapping(struct · line 2021

Quoted 8 lines
arch/arm/mm/dma-mapping.c +1 -1
@@ -2015,7 +2015,7 @@ static int extend_iommu_mapping(struct
 dma_iommu_mapping *mapping) {
 	int next_bitmap;
 
-	if (mapping->nr_bitmaps > mapping->extensions)
+	if (mapping->nr_bitmaps >= mapping->extensions)
 		return -EINVAL;
 
 	next_bitmap = mapping->nr_bitmaps;

With this patch, the error disappeared on my private arm board. Also, the fix is clearly reasonable.