beaglebone-black: works with omap2plus_defconfig and upstream kernel
[openadk.git] / target / linux / patches / 6.6.32 / armnommu-fix-thread-registers.patch
blob8ab2196dc71d454fdda2b804cac7391605ec4062
1 From 1410ebe685f13c1699a16bf147ae1332e7fd1983 Mon Sep 17 00:00:00 2001
2 From: Greg Ungerer <gerg@kernel.org>
3 Date: Thu, 20 Apr 2023 09:52:08 +1000
4 Subject: [PATCH] ARM: start_thread: restore registers on ELF load for noMMU
6 The binfmt_elf-fdpic loader is capable of loading constant displacement
7 ELF format binaries (like those compiled -pie) on noMMU systems as well
8 as elf-fdpic format binaries. The traditional ELF loader cannot be
9 enabled on noMMU systems.
11 Commit 5e588114329c ("ARM: start_thread(): don't always clear all regs")
12 fixed the start_thread() code so that it maintains the required
13 elf-fdpic registers through to the new process, but it only does that if
14 current has its personality FDPIC_FUNCPTRS bit set. That is true for
15 elf-fdpic format binaries but will not be true for non-fdpic ELF
16 binaries.
18 Modify the test of the FDPIC_FUNCPTRS personality bit to also carry out
19 the register restore if this is a noMMU system. This is not perfect,
20 since it will also preserve these registers on noMMU systems for all
21 binary format types (could be flat format for example). That won't break
22 anything, but it is potentially leaking some information into the new
23 process. But for the noMMU case we need those start time registers set to
24 be able to finalize the runtime loading of the -pie style ELF binary
25 (carry out its segment and dynamic relocation processing).
27 Unfortunately the FDPIC_FUNCPTRS flag cannot just be enabled for all
28 elf-fdpic loaded binaries. That personality bit is used for other things
29 like the controlling the changed behavior for signal handling.
31 There is no change in behavior for normal ELF loading on MMU systems.
32 A -pie style ELF binary built for noMMU systems can be load and run using
33 the usual ELF loader on an MMU system (elf-fdpic loader not required in
34 this case).
36 Signed-off-by: Greg Ungerer <gerg@kernel.org>
37 ---
38 arch/arm/include/asm/processor.h | 3 ++-
39 1 file changed, 2 insertions(+), 1 deletion(-)
41 diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
42 index 326864f79d18..5074cc3ae4e1 100644
43 --- a/arch/arm/include/asm/processor.h
44 +++ b/arch/arm/include/asm/processor.h
45 @@ -60,7 +60,8 @@ static inline void arch_thread_struct_whitelist(unsigned long *offset,
46 } \
47 memset(regs->uregs, 0, sizeof(regs->uregs)); \
48 if (IS_ENABLED(CONFIG_BINFMT_ELF_FDPIC) && \
49 - current->personality & FDPIC_FUNCPTRS) { \
50 + ((! IS_ENABLED(CONFIG_MMU)) || \
51 + current->personality & FDPIC_FUNCPTRS)) { \
52 regs->ARM_r7 = r7; \
53 regs->ARM_r8 = r8; \
54 regs->ARM_r9 = r9; \
55 --
56 2.25.1