3

I want to change the read-write-execute permissions for a specific memory region in the same process.

The following is one of the entries from /proc/pid/maps.

f606e000-f60e4000 r-xp 00000000 08:04 1873848

Is there any function to change r-xp to rwxp?

I have tried using mmap. Copy contents of the memory region. Save it to a file. Open a memory region at the exact address and size with full permissions with its contents coming from the saved file. It works but I think there should be a better way.

mtpc1486
  • 43
  • 1
  • 5
  • There is no guarantee that the kernel allows it for you. For example, in the case of shared libraries, they could be mapped into multiple processes simultanously. Could you please share some example code what you did and it doesn't work (but should)? – peterh Sep 06 '19 at 14:44
  • Other than `mmap`, also tried ptrace methods. The purpose of changing the protection is to simply change some assembly code like this: `*((void **)((uint8_t *)caller_func + 1)) = new_call_parameter;` They all sort of work but I think I just have found the answer. It is **mprotect**. – mtpc1486 Sep 06 '19 at 15:06
  • 1
    A minimal example is required for such questions. Insert a minimal example into your question. – peterh Sep 06 '19 at 15:09

0 Answers0