[PATCH] ARM: current: prevent literal references from going out of range
Ard Biesheuvel
ardb at kernel.org
Mon Dec 20 14:52:17 PST 2021
Nathan reports that the new get_current() accessor may cause problems at
build time due to the use of a literal to hold the address of the
variable that stores the 'current' pointer. This is due to the fact that
LLD before v14 does not support the PC-relative group relocations that
are normally used for this, and the fallback relies on literals without
emitting the literal pools explictly using the .ltorg directive.
Since emitting a literal pool in this particular case is not possible,
avoid the LOAD_SYM_ARMV6() entirely, and use the ordinary C assigment
instead.
While at it, add a .ltorg directive to the other instantiation of
LOAD_SYM_ARMV6(), which could potentially suffer from the same issue,
but can be fixed by an .ltorg directive due to the existence of an
unconditional branch right after it.
Fixes: 9c46929e7989 ("ARM: implement THREAD_INFO_IN_TASK for uniprocessor systems")
Reported-by: Nathan Chancellor <natechancellor at gmail.com>
Link: https://github.com/ClangBuiltLinux/linux/issues/1551
Signed-off-by: Ard Biesheuvel <ardb at kernel.org>
---
arch/arm/include/asm/current.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/arm/include/asm/current.h b/arch/arm/include/asm/current.h
index 69ecf4c6c725..6b2e4c9fae35 100644
--- a/arch/arm/include/asm/current.h
+++ b/arch/arm/include/asm/current.h
@@ -39,6 +39,7 @@ static inline __attribute_const__ struct task_struct *get_current(void)
" .subsection 1 \n\t"
"2: " LOAD_SYM_ARMV6(%0, __current) " \n\t"
" b 1b \n\t"
+ " .ltorg \n\t"
" .previous \n\t"
" .pushsection \".alt.smp.init\", \"a\" \n\t"
" .long 0b - . \n\t"
@@ -46,7 +47,8 @@ static inline __attribute_const__ struct task_struct *get_current(void)
" .popsection \n\t"
#endif
: "=r"(cur));
-#elif __LINUX_ARM_ARCH__>=7 || \
+#elif __LINUX_ARM_ARCH__>= 7 || \
+ (defined(CONFIG_LD_IS_LLD) && CONFIG_LLD_VERSION < 140000) || \
(defined(MODULE) && defined(CONFIG_ARM_MODULE_PLTS))
cur = __current;
#else
--
2.30.2
More information about the linux-arm-kernel
mailing list