Skip to content

Commit

Permalink
memory: Fix patch_code() protection flipping on RWX systems
Browse files Browse the repository at this point in the history
Just like we do in Interceptor, we should not flip to R-X afterwards.
  • Loading branch information
oleavr committed May 10, 2024
1 parent 7d9e1a4 commit 81aa79b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions gum/gummemory.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,21 @@ gum_memory_patch_code (gpointer address,

gum_clear_cache (address, size);

if (!gum_try_mprotect (start_page, range_size, GUM_PAGE_RX))
return FALSE;
if (!rwx_supported)
{
/*
* We don't bother restoring the protection on RWX systems, as we would
* have to determine the old protection to be able to do so safely.
*
* While we could easily do that, it would add overhead, but it's not
* really clear that it would have any tangible upsides.
*
* This behavior is also consistent with Interceptor, so if we later
* decide to change it, it also needs changing there.
*/
if (!gum_try_mprotect (start_page, range_size, GUM_PAGE_RX))
return FALSE;
}
}
else
{
Expand Down

0 comments on commit 81aa79b

Please sign in to comment.