Questions tagged [mprotect]
88 questions
4
votes
0 answers
Android mprotect() not changing protections
I've been trying to use mprotect() to change protections on a certain region of memory on Android.
However whatever I do I cannot cause the region to be writeable (whatever I do it still seems to remain PROT_READ|PROT_EXEC. Maybe there's something…

David Kaplan
- 81
- 1
- 6
4
votes
0 answers
Hook function call linux mint
some days ago I wrote a simple hook/detour by patching a single call instruction.
It worked on Ubuntu 12.xyz (32bit), now I updated to Linux Mint 17.1(32bit) and I get Segmentation fault.
I have two projects
target project which calls a function…

al-eax
- 712
- 5
- 13
4
votes
3 answers
C SIGSEGV Handler & Mprotect
I'm constructing a program which uses mprotect() to restrict a block of memory from accessing. When the memory is requested, a SIGSEGV is thrown which I listen for using a signal() call.
Once the SIGSEGV has been detected, I need to somehow access…

pws5068
- 2,224
- 4
- 35
- 49
4
votes
1 answer
C - Is it possible to mprotect something less than a page
And I'm really looking for any solution to this - my goal is to set an area smaller than the system's page size to PROT_READ, PROT_WRITE, PROT_EXEC or PROT_NONE. Is this possible? It seems mprotect just protects a multiple of the page size...
If…

user3475234
- 1,503
- 3
- 22
- 40
3
votes
1 answer
`mprotect`ing a custom ELF section leads to segmentation fault
I have come across this interesting StackOverflow post: How do you get the start and end addresses of a custom ELF section?
and I thought whether it might be possible to apply mprotect() to the function which is stored in the custom ELF…

Jay
- 373
- 1
- 10
3
votes
1 answer
how to get protection flags of a memory area, flags are PROT_READ /PROT_EXEC in mprotect
I use mprotect() to set protection flags to a memory area.
Later on, I want to restore this memory area's protection flags.
My question is, how to get protection flags of a memory area?
the flags inclue PROT_READ ...
My workaround is to parse…

flyingbin
- 1,097
- 2
- 11
- 28
3
votes
4 answers
mprotect API on OS X Tiger
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…
Danial
3
votes
2 answers
Make all pages readable/writable/executable
I would like to grant full permissions (read, write, and execute) to all memory pages in an ELF binary. Ideally, I'd like to be able to do this as a transformation on a binary or object file, in the same way that symbols can be changed with objcopy.…

IanPudney
- 5,941
- 1
- 24
- 39
3
votes
1 answer
Injected mprotect system call into traced process fails with EFAULT
I'm injecting an mprotect call into a traced process:
static int inject_mprotect(pid_t child, void *addr, size_t len, int prot)
{
// Machine code:
// int $0x80 (system call)
// int3 (trap)
char code[] =…

Chiggs
- 2,824
- 21
- 31
3
votes
2 answers
How to get current program counter inside mprotect handler and update it
I want to get the current program counter(PC) value inside mprotect handler. From there I want to increase the value of PC by 'n' number of instruction so that the program will skip some instructions. I want to do all that for linux kernel version…

azizulhakim
- 658
- 7
- 24
3
votes
0 answers
mprotect does not always collapse adjacent lines in /proc/pid/maps
I have a process where, after some time, a call to mprotect() fails with ENOMEM. The error is caused by "Internal kernel structures could not be allocated": at this point, the file /proc//maps contains 65531 lines, which is of course…

Armin Rigo
- 12,048
- 37
- 48
3
votes
2 answers
Protecting allocated memory
I need to allocate dynamically some portions of memory, each with some protection - either RW or RX.
I tried to allocate memory by malloc, but mprotect always returns -1 Invalid argument.
My sample code:
void *x = malloc(getpagesize());
mprotect(x,…

Ari
- 3,101
- 2
- 27
- 49
3
votes
1 answer
C write/read detection on memory block
i like to ask if someone have any idea how to detect a write on alloc memory address.
At first i used mprotect along with sigaction to force a segmentation fault when was made a write/read operation.
Two negative factor with this approach among…

Majao
- 31
- 4
2
votes
1 answer
SIGSEGV handler and mprotect and looping effect when injecting instructions at runtime. Handler can't get info->si_addr
I have looked at the various topics relating to this, but couldn't find this specific issue I am having.
Things I looked at:
Injecting code into executable at runtime
C SIGSEGV Handler & Mprotect
Can I write-protect every page in the address space…

Setzer
- 739
- 4
- 10
- 18
2
votes
3 answers
run `make qemu` got error: `qemu_mprotect__osdep: mprotect failed: Permission denied`
I am trying do mit6.828 lab on mac m1. After installed riscv-tool-chain, I tried to run make qemu which seems to be used start the kernel, but at first I got this error:
mkfs/mkfs fs.img README user/xargstest.sh user/_cat user/_echo user/_forktest…

Rezero
- 150
- 12