Reputation:
I'm trying to use mprotect API on MacOSX 10.4 (tiger), I tried every possible way I know , it always returns -1, with errno 13, which means "permission denied" while I'm trying to add the write permission to some executable code.
The same code exactly works on MacOS X 10.5 (leopard).
the code is pretty simple
int ret = mprotect((void*)pFunc, 4096, PROT_WRITE | PROT_EXEC);
where pFunc is the address of any function loaded in the process address space. I tried to remove the PROT_EXEC before adding the PROT_WRITE access right, but no luck. I also tried aligning pFunc with the memory page size, no luck neither..
Any idea how to make this working?
Upvotes: 3
Views: 1441
Reputation: 54345
Here is another idea. Try marking it EXEC without the WRITE. I think denying write+exec may be a security feature.
To write to it then, mark it as WRITE but not EXEC.
Upvotes: 0
Reputation: 14122
Is the memory you are trying to modify mmap'd from the executable? The man page for mprotect (on Linux) seems to indicate that this would prevent you from modifying (PROT_WRITE) the memory location.
Upvotes: 1
Reputation: 249394
You do not have permission to write into executable regions. Anyway, why should you?
I'm sure this works on some platforms, but not all. What are you trying to do?
Upvotes: 0
Reputation: 135375
I know nothing about OSX. That said, can you use the Mach function vm_protect?
Upvotes: 0