| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 | From ab7647c2b04501297c50ce7cdb6f6895b9582d22 Mon Sep 17 00:00:00 2001From: Greg Ungerer <gerg@kernel.org>Date: Fri, 21 Apr 2023 00:21:38 +1000Subject: [PATCH] fs: binfmt_elf_efpic: fix personality for fdpic ELFThe elf-fdpic loader hard sets the process personality to eitherPER_LINUX_FDPIC for true elf-fdpic binaries or to PER_LINUX fornormal ELF binaries (in this case they would be constant displacementcompiled with -pie for example). The problem with that is that itwill lose any other bits that may be in the ELF header personality(such as the "bug emulation" bits).On the ARM architecture the ADDR_LIMIT_32BIT flag is used to signifya normal 32bit binary - as opposed to a legacy 26bit address binary.This matters since start_thread() will set the ARM CPSR register asrequired based on this flag. If the elf-fdpic loader loses this bitthe process will be mis-configured and crash out pretty quickly.Modify elf-fdpic loaders personality setting binaries so that itpreserves the upper three bytes by using the SET_PERSONALITY macroto set it. This macro in the generic case sets PER_LINUX and preservesthe upper bytes. Architectures can override this for their specificuse case, and ARM does exactly this.The problem shows up quite easily runing under qemu, but not necessarilyon all types of real ARM hardware. If the underlying ARM processor doesnot support the legacy 26-bit addressing mode then everyting will workas expected.Signed-off-by: Greg Ungerer <gerg@kernel.org>--- fs/binfmt_elf_fdpic.c |    5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.cindex a05eafcacfb2..f29ae1d96fd7 100644--- a/fs/binfmt_elf_fdpic.c+++ b/fs/binfmt_elf_fdpic.c@@ -345,10 +345,9 @@ 	/* there's now no turning back... the old userspace image is dead, 	 * defunct, deceased, etc. 	 */+	SET_PERSONALITY(exec_params.hdr); 	if (elf_check_fdpic(&exec_params.hdr))-		set_personality(PER_LINUX_FDPIC);-	else-		set_personality(PER_LINUX);+		current->personality |= PER_LINUX_FDPIC; 	if (elf_read_implies_exec(&exec_params.hdr, executable_stack)) 		current->personality |= READ_IMPLIES_EXEC; -- 2.25.1
 |