Skip to contentSkip to conversation

arm64: cputype: Avoid overflow using MIDR_IMPLEMENTOR_MASK

PATCH Applied Michal Orzel 2 participants 3 messages Apr 26, 2022 – May 4, 2022 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: cputype: Avoid overflow using MIDR_IMPLEMENTOR_MASK

Value of macro MIDR_IMPLEMENTOR_MASK exceeds the range of integer and can lead to overflow. Currently there is no issue as it is used in expressions implicitly casting it to u32. To avoid possible problems, fix the macro.

---
Should we also add a U suffix to ARM_CPU_IMP_* macros that are also shifted by MIDR_IMPLEMENTOR_SHIFT? None of them has bit 7 set but we could take some precaution steps.

---
 arch/arm64/include/asm/cputype.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/cputype.h +1 -1
index ff8f4511df71..92331c07c2d1 100644
@@ -36,7 +36,7 @@
 #define MIDR_VARIANT(midr)	\
 	(((midr) & MIDR_VARIANT_MASK) >> MIDR_VARIANT_SHIFT)
 #define MIDR_IMPLEMENTOR_SHIFT	24
-#define MIDR_IMPLEMENTOR_MASK	(0xff << MIDR_IMPLEMENTOR_SHIFT)
+#define MIDR_IMPLEMENTOR_MASK	(0xffU << MIDR_IMPLEMENTOR_SHIFT)
 #define MIDR_IMPLEMENTOR(midr)	\
 	(((midr) & MIDR_IMPLEMENTOR_MASK) >> MIDR_IMPLEMENTOR_SHIFT)
 
Signature · 7 lines
2.25.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer
#1 lore raw
Quoted 10 lines · Michal Orzel

Value of macro MIDR_IMPLEMENTOR_MASK exceeds the range of integer and can lead to overflow. Currently there is no issue as it is used in expressions implicitly casting it to u32. To avoid possible problems, fix the macro.

---
Should we also add a U suffix to ARM_CPU_IMP_* macros that are also shifted by MIDR_IMPLEMENTOR_SHIFT? None of them has bit 7 set but we could take some precaution steps.

I'm ok with not adding it now. We haven't been consistent with this but we did encounter a few issues in the past with other bits and only fixed those that were touching bit 31.

Signature · 1 line
Catalin
maintainer Applied
#2 lore raw
In reply to Michal Orzel
Quoted 6 lines · Michal Orzel

Value of macro MIDR_IMPLEMENTOR_MASK exceeds the range of integer and can lead to overflow. Currently there is no issue as it is used in expressions implicitly casting it to u32. To avoid possible problems, fix the macro.

Applied to arm64 (for-next/misc), thanks!

[1/1] arm64: cputype: Avoid overflow using MIDR_IMPLEMENTOR_MASK

      https://git.kernel.org/arm64/c/48e6f22e25a4
Signature · 1 line
Catalin