armnommu-fix-thread-registers.patch 2.5 KB

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