diff options
-rw-r--r-- | src/execstack.c | 63 | ||||
-rw-r--r-- | src/space.c | 7 |
2 files changed, 48 insertions, 22 deletions
diff --git a/src/execstack.c b/src/execstack.c index 1f50acd..9f8bf7e 100644 --- a/src/execstack.c +++ b/src/execstack.c @@ -283,6 +283,16 @@ execstack_set (DSO *dso, int flag) { /* There is enough space for the headers even without reshuffling anything. */ + for (i = 0; i < dso->ehdr.e_phnum; ++i) + if (dso->phdr[i].p_type == PT_PHDR) + { + if (dso->phdr[i].p_filesz + == dso->ehdr.e_phnum * dso->ehdr.e_phentsize) + dso->phdr[i].p_filesz += dso->ehdr.e_phentsize; + if (dso->phdr[i].p_memsz + == dso->ehdr.e_phnum * dso->ehdr.e_phentsize) + dso->phdr[i].p_memsz += dso->ehdr.e_phentsize; + } i = dso->ehdr.e_phnum++; ret = execstack_make_rdwr (dso, flag); if (ret != -1) @@ -308,28 +318,37 @@ execstack_set (DSO *dso, int flag) to overlap on the same page. */ last = -1; for (i = 0; i < dso->ehdr.e_phnum; ++i) - if (dso->phdr[i].p_type == PT_LOAD - && dso->phdr[i].p_vaddr + dso->phdr[i].p_memsz >= start) - { - if (last != -1 - && (((dso->phdr[last].p_vaddr + dso->phdr[last].p_memsz - 1) - ^ dso->phdr[i].p_vaddr) - & ~(dso->arch->max_page_size - 1)) - && !(((dso->phdr[last].p_vaddr + dso->phdr[last].p_memsz - + adjust - 1) - ^ (dso->phdr[i].p_vaddr + adjust)) - & ~(dso->arch->max_page_size - 1))) - { - if (align >= dso->arch->max_page_size) - { - error (0, 0, "%s: Cannot grow reloc sections", dso->filename); - goto error_out; - } - adjust = (adjust + dso->arch->max_page_size - 1) - & ~(dso->arch->max_page_size - 1); - } - last = i; - } + if (dso->phdr[i].p_type == PT_LOAD + && dso->phdr[i].p_vaddr + dso->phdr[i].p_memsz >= start) + { + if (last != -1 + && (((dso->phdr[last].p_vaddr + dso->phdr[last].p_memsz - 1) + ^ dso->phdr[i].p_vaddr) + & ~(dso->arch->max_page_size - 1)) + && !(((dso->phdr[last].p_vaddr + dso->phdr[last].p_memsz + + adjust - 1) + ^ (dso->phdr[i].p_vaddr + adjust)) + & ~(dso->arch->max_page_size - 1))) + { + if (align >= dso->arch->max_page_size) + { + error (0, 0, "%s: Cannot grow reloc sections", dso->filename); + goto error_out; + } + adjust = (adjust + dso->arch->max_page_size - 1) + & ~(dso->arch->max_page_size - 1); + } + last = i; + } + + for (i = 0; i < dso->ehdr.e_phnum; ++i) + if (dso->phdr[i].p_type == PT_PHDR) + { + if (dso->phdr[i].p_filesz == dso->ehdr.e_phnum * dso->ehdr.e_phentsize) + dso->phdr[i].p_filesz += dso->ehdr.e_phentsize; + if (dso->phdr[i].p_memsz == dso->ehdr.e_phnum * dso->ehdr.e_phentsize) + dso->phdr[i].p_memsz += dso->ehdr.e_phentsize; + } i = dso->ehdr.e_phnum++; ret = execstack_make_rdwr (dso, flag); diff --git a/src/space.c b/src/space.c index 7ceb131..bf76a41 100644 --- a/src/space.c +++ b/src/space.c @@ -635,6 +635,13 @@ find_readonly_space (DSO *dso, GElf_Shdr *add, GElf_Ehdr *ehdr, for (i = 0, j = 0; i < ehdr->e_phnum; ++i) if (phdr[i].p_type == PT_LOAD) j = i; + else if (phdr[i].p_type == PT_PHDR) + { + if (phdr[i].p_filesz == ehdr->e_phnum * ehdr->e_phentsize) + phdr[i].p_filesz += ehdr->e_phentsize; + if (phdr[i].p_memsz == ehdr->e_phnum * ehdr->e_phentsize) + phdr[i].p_memsz += ehdr->e_phentsize; + } memmove (&phdr[j + 2], &phdr[j + 1], (ehdr->e_phnum - j - 1) * sizeof (GElf_Phdr)); |