From d41b9e441e9103be4ae760bd356c096d4e8bd259 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Mon, 16 Jan 2023 17:03:33 +0000 Subject: [PATCH] ANDROID: arm64: Disallow use of backported SYS_FIELD_*() access macros These are dangerous because they assume mask macros are pre-shifted, GENMASK style. Most of the masks in this kernel tree are not shifted. Avoid accidental buggy backports in future by turning the SYS_FIELD accessors into BUILD_BUG(). Signed-off-by: Keir Fraser Bug: 233588291 Fixes: 1bf4f91abe973 ("UPSTREAM: arm64/sysreg: Introduce helpers for access to sysreg fields") Change-Id: I647a66d59279e69c916f66b42705fc20cd256fa8 --- arch/arm64/include/asm/sysreg.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index 67e5ebe25097..1479f5c89cea 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -1430,14 +1430,20 @@ par; \ }) +/* + * Disallow any use of the following backported SYS_FIELD macros. They rely on + * use of pre-shifted masked (for example, as generated by GENMASK). Most of + * the masks defined in this tree are not shifted, making these macros subtly + * dangerous! + */ #define SYS_FIELD_GET(reg, field, val) \ - FIELD_GET(reg##_##field##_MASK, val) + BUILD_BUG() #define SYS_FIELD_PREP(reg, field, val) \ - FIELD_PREP(reg##_##field##_MASK, val) + BUILD_BUG() #define SYS_FIELD_PREP_ENUM(reg, field, val) \ - FIELD_PREP(reg##_##field##_MASK, reg##_##field##_##val) + BUILD_BUG() #endif