linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: linux-arm-kernel@lists.infradead.org
Cc: arnd@arndb.de, linux@armlinux.org.uk,
	Ard Biesheuvel <ardb@kernel.org>,
	Nathan Chancellor <natechancellor@gmail.com>
Subject: [PATCH] ARM: current: prevent literal references from going out of range
Date: Mon, 20 Dec 2021 23:52:17 +0100	[thread overview]
Message-ID: <20211220225217.458335-1-ardb@kernel.org> (raw)

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@gmail.com>
Link: https://github.com/ClangBuiltLinux/linux/issues/1551
Signed-off-by: Ard Biesheuvel <ardb@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


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

                 reply	other threads:[~2021-12-20 22:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211220225217.458335-1-ardb@kernel.org \
    --to=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=natechancellor@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).