From 81aa79b73142c5da9fe1107d1ebce5dd247c4aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Fri, 10 May 2024 17:26:14 +0200 Subject: [PATCH] memory: Fix patch_code() protection flipping on RWX systems Just like we do in Interceptor, we should not flip to R-X afterwards. --- gum/gummemory.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/gum/gummemory.c b/gum/gummemory.c index 32d79c126..26c800dd5 100644 --- a/gum/gummemory.c +++ b/gum/gummemory.c @@ -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 {