Skip to content

Commit

Permalink
Merge pull request #130 from LLNL/bugfix/mark_got_writable
Browse files Browse the repository at this point in the history
Combining marking GOT and PLT GOT writable
  • Loading branch information
hariharan-devarajan authored Oct 3, 2023
2 parents 61703fb + 9c0943a commit 815cdac
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/gotcha.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,15 @@ static int mark_got_writable(struct link_map *lib) {
}
ElfW(Addr) got_addr =
BOUNDARY_BEFORE(boundary.start_addr, (ElfW(Addr))page_size);
ElfW(Addr) got_size = got_end - got_addr + 1;
ElfW(Addr) got_size = got_end - got_addr;
/**
* The next two cases are to optimize mprotect calls to do both pages
* together if they align. We do not have such usecase yet and hence
* ignoring from coverage.
*/
if (got_addr == plt_got_addr + plt_got_size) {
// Haven't seen a library till now where got_addr > plt_got_addr
// GCOVR_EXCL_START
debug_printf(3,
"Setting library %s GOT and PLT table "
"from %p to +%lu to writeable\n",
Expand All @@ -301,14 +303,15 @@ static int mark_got_writable(struct link_map *lib) {
int res = gotcha_mprotect((void *)plt_got_addr, plt_got_size + got_size,
PROT_READ | PROT_WRITE | PROT_EXEC);
// mprotect returns -1 on an error
if (res == -1) { // GCOVR_EXCL_START
if (res == -1) {
error_printf(
"GOTCHA attempted to mark both GOT and PLT GOT tables as writable "
"and was unable to do so, "
"calls to wrapped functions may likely fail.\n");
} // GCOVR_EXCL_STOP
plt_got_written = 1;
}
plt_got_written = 1; // GCOVR_EXCL_STOP
} else if (plt_got_addr == got_addr + got_size) {
// This is a more common case.
debug_printf(3,
"Setting library %s GOT and PLT table "
"from %p to +%lu to writeable\n",
Expand Down

0 comments on commit 815cdac

Please sign in to comment.