| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 | From 1410ebe685f13c1699a16bf147ae1332e7fd1983 Mon Sep 17 00:00:00 2001From: Greg Ungerer <gerg@kernel.org>Date: Thu, 20 Apr 2023 09:52:08 +1000Subject: [PATCH] ARM: start_thread: restore registers on ELF load for noMMUThe binfmt_elf-fdpic loader is capable of loading constant displacementELF format binaries (like those compiled -pie) on noMMU systems as wellas elf-fdpic format binaries. The traditional ELF loader cannot beenabled on noMMU systems.Commit 5e588114329c ("ARM: start_thread(): don't always clear all regs")fixed the start_thread() code so that it maintains the requiredelf-fdpic registers through to the new process, but it only does that ifcurrent has its personality FDPIC_FUNCPTRS bit set. That is true forelf-fdpic format binaries but will not be true for non-fdpic ELFbinaries.Modify the test of the FDPIC_FUNCPTRS personality bit to also carry outthe register restore if this is a noMMU system. This is not perfect,since it will also preserve these registers on noMMU systems for allbinary format types (could be flat format for example). That won't breakanything, but it is potentially leaking some information into the newprocess. But for the noMMU case we need those start time registers set tobe able to finalize the runtime loading of the -pie style ELF binary(carry out its segment and dynamic relocation processing).Unfortunately the FDPIC_FUNCPTRS flag cannot just be enabled for allelf-fdpic loaded binaries. That personality bit is used for other thingslike the controlling the changed behavior for signal handling.There is no change in behavior for normal ELF loading on MMU systems.A -pie style ELF binary built for noMMU systems can be load and run usingthe usual ELF loader on an MMU system (elf-fdpic loader not required inthis case).Signed-off-by: Greg Ungerer <gerg@kernel.org>--- arch/arm/include/asm/processor.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.hindex 326864f79d18..5074cc3ae4e1 100644--- a/arch/arm/include/asm/processor.h+++ b/arch/arm/include/asm/processor.h@@ -60,7 +60,8 @@ static inline void arch_thread_struct_whitelist(unsigned long *offset, 	}								\ 	memset(regs->uregs, 0, sizeof(regs->uregs));			\ 	if (IS_ENABLED(CONFIG_BINFMT_ELF_FDPIC) &&			\-	    current->personality & FDPIC_FUNCPTRS) {			\+	    ((! IS_ENABLED(CONFIG_MMU)) ||				\+	     current->personality & FDPIC_FUNCPTRS)) {			\ 		regs->ARM_r7 = r7;					\ 		regs->ARM_r8 = r8;					\ 		regs->ARM_r9 = r9;					\-- 2.25.1
 |