150-fix-ldso-text-realloc-segfault.patch 1.4 KB

1234567891011121314151617181920212223242526272829
  1. --- a/ldso/ldso/ldso.c
  2. +++ b/ldso/ldso/ldso.c
  3. @@ -286,15 +286,20 @@ void _dl_get_ready_to_run(struct elf_res
  4. _dl_debug_early("calling mprotect on the application program\n");
  5. /* Now cover the application program. */
  6. if (app_tpnt->dynamic_info[DT_TEXTREL]) {
  7. - ppnt = (ElfW(Phdr) *) auxvt[AT_PHDR].a_un.a_val;
  8. - for (i = 0; i < auxvt[AT_PHNUM].a_un.a_val; i++, ppnt++) {
  9. - if (ppnt->p_type == PT_LOAD && !(ppnt->p_flags & PF_W))
  10. - _dl_mprotect((void *) (DL_RELOC_ADDR(app_tpnt->loadaddr, ppnt->p_vaddr) & PAGE_ALIGN),
  11. - ((ppnt->p_vaddr + app_tpnt->loadaddr) & ADDR_ALIGN) +
  12. - (unsigned long) ppnt->p_filesz,
  13. + ElfW(Phdr) *ppnt_inner = (ElfW(Phdr) *) auxvt[AT_PHDR].a_un.a_val;
  14. + for (i = 0; i < auxvt[AT_PHNUM].a_un.a_val; i++, ppnt_inner++) {
  15. + if (ppnt_inner->p_type == PT_LOAD && !(ppnt_inner->p_flags & PF_W))
  16. + _dl_mprotect((void *) (DL_RELOC_ADDR(app_tpnt->loadaddr, ppnt_inner->p_vaddr) & PAGE_ALIGN),
  17. + ((ppnt_inner->p_vaddr + app_tpnt->loadaddr) & ADDR_ALIGN) +
  18. + (unsigned long) ppnt_inner->p_filesz,
  19. PROT_READ | PROT_WRITE | PROT_EXEC);
  20. }
  21. }
  22. +#else
  23. + if (app_tpnt->dynamic_info[DT_TEXTREL]) {
  24. + _dl_dprintf(_dl_debug_file, "Can't modify application's text section; use the GCC option -fPIE for position-independent executables.\n");
  25. + _dl_exit(1);
  26. +}
  27. #endif
  28. #ifndef ALLOW_ZERO_PLTGOT