Exemplo n.º 1
0
void relro_post()
{
    mprotect_cb(relro_start, relro_end - relro_start, PROT_READ);
    // mprotect_cb is a pointer allocated in .bss, so we need to restore it to
    // a NULL value.
    mprotect_cb = NULL;
}
Exemplo n.º 2
0
void relro_pre()
{
    // By the time the injected code runs, the relro segment is read-only. But
    // we want to apply relocations in it, so we set it r/w first. We'll restore
    // it to read-only in relro_post.
    mprotect_cb(relro_start, relro_end - relro_start, PROT_READ | PROT_WRITE);
}
Exemplo n.º 3
0
static inline __attribute__((always_inline)) void do_relocations_with_relro(
    void) {
  long page_size = sysconf_cb(_SC_PAGESIZE);
  uintptr_t aligned_relro_start = ((uintptr_t)relro_start) & ~(page_size - 1);
  // The relro segment may not end at a page boundary. If that's the case, the
  // remainder of the page needs to stay read-write, so the last page is never
  // set read-only. Thus the aligned relro end is page-rounded down.
  uintptr_t aligned_relro_end = ((uintptr_t)relro_end) & ~(page_size - 1);
  // By the time the injected code runs, the relro segment is read-only. But
  // we want to apply relocations in it, so we set it r/w first. We'll restore
  // it to read-only in relro_post.
  mprotect_cb((void*)aligned_relro_start,
              aligned_relro_end - aligned_relro_start, PROT_READ | PROT_WRITE);

  do_relocations();

  mprotect_cb((void*)aligned_relro_start,
              aligned_relro_end - aligned_relro_start, PROT_READ);
  // mprotect_cb and sysconf_cb are allocated in .bss, so we need to restore
  // them to a NULL value.
  mprotect_cb = NULL;
  sysconf_cb = NULL;
}