Skip to contentSkip to conversation

ARM: Fix MAX_DMA_ADDRESS overflow

PATCH Superseded Florian Fainelli 2 participants 5 messages Jul 6, 2022 Arm (32-bit)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ARM: Fix MAX_DMA_ADDRESS overflow

Commit 26f09e9b3a06 ("mm/memblock: add memblock memory allocation apis") added a check to determine whether arm_dma_zone_size is exceeding the amount of kernel virtual address space available between the upper 4GB virtual address limit and PAGE_OFFSET in order to provide a suitable definition of MAX_DMA_ADDRESS that should fit within the 32-bit virtual address space. The quantity used for comparison was off by a missing trailing 0, leading to MAX_DMA_ADDRESS to be overflowing a 32-bit quantity.

This was caught with the bcm2711 platforms which defines a dma_zone_size of 1GB, and using a PAGE_OFFSET of 0xc000_0000 (CONFIG_VMSPLIT_3G) with CONFIG_DEBUG_VIRTUAL enabled would lead to MAX_DMA_ADDRESS being 0x1_0000_0000 which overflows the unsigned long type used throughout __pa() and __virt_addr_valid(). Because the virtual address passed to __virt_addr_valid() would now be 0, the function would loudly warn, thus making the platform unable to boot properly.

Fixes 26f09e9b3a06 ("mm/memblock: add memblock memory allocation apis")

---
Changes in v2:

- simplify the patch and drop the first patch that attempted to fix an off by one in the calculation.

 arch/arm/include/asm/dma.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/include/asm/dma.h +1 -1
index a81dda65c576..1ffa75beb709 100644
@@ -10,7 +10,7 @@
 #else
 #define MAX_DMA_ADDRESS	({ \
 	extern phys_addr_t arm_dma_zone_size; \
-	arm_dma_zone_size && arm_dma_zone_size < (0x10000000 - PAGE_OFFSET) ? \
+	arm_dma_zone_size && arm_dma_zone_size < (0x100000000 - PAGE_OFFSET) ? \
 		(PAGE_OFFSET + arm_dma_zone_size) : 0xffffffffUL; })
 #endif
 
Signature · 1 line
2.25.1
#1 lore raw

Hi Florian,

Quoted 17 lines · Florian Fainelli

Commit 26f09e9b3a06 ("mm/memblock: add memblock memory allocation apis") added a check to determine whether arm_dma_zone_size is exceeding the amount of kernel virtual address space available between the upper 4GB virtual address limit and PAGE_OFFSET in order to provide a suitable definition of MAX_DMA_ADDRESS that should fit within the 32-bit virtual address space. The quantity used for comparison was off by a missing trailing 0, leading to MAX_DMA_ADDRESS to be overflowing a 32-bit quantity.

This was caught with the bcm2711 platforms which defines a dma_zone_size of 1GB, and using a PAGE_OFFSET of 0xc000_0000 (CONFIG_VMSPLIT_3G) with CONFIG_DEBUG_VIRTUAL enabled would lead to MAX_DMA_ADDRESS being 0x1_0000_0000 which overflows the unsigned long type used throughout __pa() and __virt_addr_valid(). Because the virtual address passed to __virt_addr_valid() would now be 0, the function would loudly warn, thus making the platform unable to boot properly.

Quoted 7 lines
Fixes 26f09e9b3a06 ("mm/memblock: add memblock memory allocation apis")

---
Changes in v2:

- simplify the patch and drop the first patch that attempted to fix an off by one in the calculation.

Thanks for the update!

arch/arm/include/asm/dma.h line 13

Quoted 7 lines
arch/arm/include/asm/dma.h +0 -1
@@ -10,7 +10,7 @@
 #else
 #define MAX_DMA_ADDRESS        ({ \
        extern phys_addr_t arm_dma_zone_size; \
-       arm_dma_zone_size && arm_dma_zone_size < (0x10000000 - PAGE_OFFSET) ? \
                                                  ^^^^^^^^^^

0x10000000ULL, as the constant doesn't fit in 32-bit. However, both gcc (9.4.0) and sparse don't seem to complain about the missing suffix (anymore?).

arch/arm/include/asm/dma.h line 15

Quoted 3 lines
arch/arm/include/asm/dma.h +1 -0
+       arm_dma_zone_size && arm_dma_zone_size < (0x100000000 - PAGE_OFFSET) ? \
                (PAGE_OFFSET + arm_dma_zone_size) : 0xffffffffUL; })
 #endif

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#2 lore raw
Quoted 36 lines · Geert Uytterhoeven
Quoted 17 lines · Florian Fainelli

Commit 26f09e9b3a06 ("mm/memblock: add memblock memory allocation apis") added a check to determine whether arm_dma_zone_size is exceeding the amount of kernel virtual address space available between the upper 4GB virtual address limit and PAGE_OFFSET in order to provide a suitable definition of MAX_DMA_ADDRESS that should fit within the 32-bit virtual address space. The quantity used for comparison was off by a missing trailing 0, leading to MAX_DMA_ADDRESS to be overflowing a 32-bit quantity.

This was caught with the bcm2711 platforms which defines a dma_zone_size of 1GB, and using a PAGE_OFFSET of 0xc000_0000 (CONFIG_VMSPLIT_3G) with CONFIG_DEBUG_VIRTUAL enabled would lead to MAX_DMA_ADDRESS being 0x1_0000_0000 which overflows the unsigned long type used throughout __pa() and __virt_addr_valid(). Because the virtual address passed to __virt_addr_valid() would now be 0, the function would loudly warn, thus making the platform unable to boot properly.

Quoted 7 lines
Fixes 26f09e9b3a06 ("mm/memblock: add memblock memory allocation apis")

---
Changes in v2:

- simplify the patch and drop the first patch that attempted to fix an off by one in the calculation.

Thanks for the update!

arch/arm/include/asm/dma.h line 13

Quoted 7 lines
arch/arm/include/asm/dma.h +0 -1
@@ -10,7 +10,7 @@
 #else
 #define MAX_DMA_ADDRESS        ({ \
        extern phys_addr_t arm_dma_zone_size; \
-       arm_dma_zone_size && arm_dma_zone_size < (0x10000000 - PAGE_OFFSET) ? \
                                                  ^^^^^^^^^^
Quoted 5 lines

0x10000000ULL, as the constant doesn't fit in 32-bit. However, both gcc (9.4.0) and sparse don't seem to complain about the missing suffix (anymore?).

Quoted 1 line
arch/arm/include/asm/dma.h +1 -0
+       arm_dma_zone_size && arm_dma_zone_size < (0x100000000 - PAGE_OFFSET) ? \

Obviously my comment applies to the _new_ line, not to the removed line...

Quoted 2 lines

arch/arm/include/asm/dma.h line 15

Quoted 2 lines
arch/arm/include/asm/dma.h +0 -0
                (PAGE_OFFSET + arm_dma_zone_size) : 0xffffffffUL; })
 #endif

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#3 lore raw
In reply to Geert Uytterhoeven
Quoted 38 lines · Geert Uytterhoeven

Hi Florian,

Quoted 17 lines · Florian Fainelli

Commit 26f09e9b3a06 ("mm/memblock: add memblock memory allocation apis") added a check to determine whether arm_dma_zone_size is exceeding the amount of kernel virtual address space available between the upper 4GB virtual address limit and PAGE_OFFSET in order to provide a suitable definition of MAX_DMA_ADDRESS that should fit within the 32-bit virtual address space. The quantity used for comparison was off by a missing trailing 0, leading to MAX_DMA_ADDRESS to be overflowing a 32-bit quantity.

This was caught with the bcm2711 platforms which defines a dma_zone_size of 1GB, and using a PAGE_OFFSET of 0xc000_0000 (CONFIG_VMSPLIT_3G) with CONFIG_DEBUG_VIRTUAL enabled would lead to MAX_DMA_ADDRESS being 0x1_0000_0000 which overflows the unsigned long type used throughout __pa() and __virt_addr_valid(). Because the virtual address passed to __virt_addr_valid() would now be 0, the function would loudly warn, thus making the platform unable to boot properly.

Quoted 7 lines
Fixes 26f09e9b3a06 ("mm/memblock: add memblock memory allocation apis")

---
Changes in v2:

- simplify the patch and drop the first patch that attempted to fix an off by one in the calculation.

Thanks for the update!

arch/arm/include/asm/dma.h line 13

Quoted 7 lines
arch/arm/include/asm/dma.h +0 -1
@@ -10,7 +10,7 @@
  #else
  #define MAX_DMA_ADDRESS        ({ \
         extern phys_addr_t arm_dma_zone_size; \
-       arm_dma_zone_size && arm_dma_zone_size < (0x10000000 - PAGE_OFFSET) ? \
                                                   ^^^^^^^^^^
Quoted 3 lines

0x10000000ULL, as the constant doesn't fit in 32-bit. However, both gcc (9.4.0) and sparse don't seem to complain about the missing suffix (anymore?).

Thanks, I will the ULL suffix in v3.

Signature · 1 line
Florian
#4 lore raw

Hi Florian,

Quoted 41 lines · Florian Fainelli
Quoted 36 lines · Geert Uytterhoeven
Quoted 17 lines · Florian Fainelli

Commit 26f09e9b3a06 ("mm/memblock: add memblock memory allocation apis") added a check to determine whether arm_dma_zone_size is exceeding the amount of kernel virtual address space available between the upper 4GB virtual address limit and PAGE_OFFSET in order to provide a suitable definition of MAX_DMA_ADDRESS that should fit within the 32-bit virtual address space. The quantity used for comparison was off by a missing trailing 0, leading to MAX_DMA_ADDRESS to be overflowing a 32-bit quantity.

This was caught with the bcm2711 platforms which defines a dma_zone_size of 1GB, and using a PAGE_OFFSET of 0xc000_0000 (CONFIG_VMSPLIT_3G) with CONFIG_DEBUG_VIRTUAL enabled would lead to MAX_DMA_ADDRESS being 0x1_0000_0000 which overflows the unsigned long type used throughout __pa() and __virt_addr_valid(). Because the virtual address passed to __virt_addr_valid() would now be 0, the function would loudly warn, thus making the platform unable to boot properly.

Quoted 7 lines
Fixes 26f09e9b3a06 ("mm/memblock: add memblock memory allocation apis")

---
Changes in v2:

- simplify the patch and drop the first patch that attempted to fix an off by one in the calculation.

Thanks for the update!

arch/arm/include/asm/dma.h line 13

Quoted 7 lines
arch/arm/include/asm/dma.h +0 -1
@@ -10,7 +10,7 @@
  #else
  #define MAX_DMA_ADDRESS        ({ \
         extern phys_addr_t arm_dma_zone_size; \
-       arm_dma_zone_size && arm_dma_zone_size < (0x10000000 - PAGE_OFFSET) ? \
                                                   ^^^^^^^^^^
Quoted 3 lines

0x10000000ULL, as the constant doesn't fit in 32-bit. However, both gcc (9.4.0) and sparse don't seem to complain about the missing suffix (anymore?).

Quoted 1 line

Thanks, I will the ULL suffix in v3.

I just remembered the suffix is not needed (but doesn't hurt), because hexadecimal constants automatically have the right unsigned type.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds