armnommu-fix-elf-fdpic-personality.patch 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. From ab7647c2b04501297c50ce7cdb6f6895b9582d22 Mon Sep 17 00:00:00 2001
  2. From: Greg Ungerer <gerg@kernel.org>
  3. Date: Fri, 21 Apr 2023 00:21:38 +1000
  4. Subject: [PATCH] fs: binfmt_elf_efpic: fix personality for fdpic ELF
  5. The elf-fdpic loader hard sets the process personality to either
  6. PER_LINUX_FDPIC for true elf-fdpic binaries or to PER_LINUX for
  7. normal ELF binaries (in this case they would be constant displacement
  8. compiled with -pie for example). The problem with that is that it
  9. will lose any other bits that may be in the ELF header personality
  10. (such as the "bug emulation" bits).
  11. On the ARM architecture the ADDR_LIMIT_32BIT flag is used to signify
  12. a normal 32bit binary - as opposed to a legacy 26bit address binary.
  13. This matters since start_thread() will set the ARM CPSR register as
  14. required based on this flag. If the elf-fdpic loader loses this bit
  15. the process will be mis-configured and crash out pretty quickly.
  16. Modify elf-fdpic loaders personality setting binaries so that it
  17. preserves the upper three bytes by using the SET_PERSONALITY macro
  18. to set it. This macro in the generic case sets PER_LINUX and preserves
  19. the upper bytes. Architectures can override this for their specific
  20. use case, and ARM does exactly this.
  21. The problem shows up quite easily runing under qemu, but not necessarily
  22. on all types of real ARM hardware. If the underlying ARM processor does
  23. not support the legacy 26-bit addressing mode then everyting will work
  24. as expected.
  25. Signed-off-by: Greg Ungerer <gerg@kernel.org>
  26. ---
  27. fs/binfmt_elf_fdpic.c | 5 ++---
  28. 1 file changed, 2 insertions(+), 3 deletions(-)
  29. diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
  30. index a05eafcacfb2..f29ae1d96fd7 100644
  31. --- a/fs/binfmt_elf_fdpic.c
  32. +++ b/fs/binfmt_elf_fdpic.c
  33. @@ -345,10 +345,9 @@
  34. /* there's now no turning back... the old userspace image is dead,
  35. * defunct, deceased, etc.
  36. */
  37. + SET_PERSONALITY(exec_params.hdr);
  38. if (elf_check_fdpic(&exec_params.hdr))
  39. - set_personality(PER_LINUX_FDPIC);
  40. - else
  41. - set_personality(PER_LINUX);
  42. + current->personality |= PER_LINUX_FDPIC;
  43. if (elf_read_implies_exec(&exec_params.hdr, executable_stack))
  44. current->personality |= READ_IMPLIES_EXEC;
  45. --
  46. 2.25.1