Questions tagged [mprotect]
88 questions
1
vote
0 answers
Having issues with mmap from within a function
I'm trying to write a function that has mmap within it, however when I try to access the memory from main(), it gets a segfault. Does anyone have any idea why?
Please ignore the MPI headers - it's for the later part of the project. I have commented…

Will James
- 9
- 1
1
vote
0 answers
Anomalous Bus Error for accessing protected memory on macOS?
Context
I've written a small program with the intention of using it to generate a SIGSEGV signal, which I'll catch with a handler and then print out.
Problem
The program I wrote works fine (or so it seems) on Linux. However, when compiled and…

Micrified
- 3,338
- 4
- 33
- 59
1
vote
2 answers
Do I need to reset protection before calling free
I allocated some large chunks of memory through malloc and aligned_alloc, and then I setup a fence to a region inside the memory with size of one page size, using mprotect:
void *buf = malloc(128 * PAGE_SIZE);
int ret = mprotect(buf, PAGE_SIZE,…

fluter
- 13,238
- 8
- 62
- 100
1
vote
0 answers
How do you query memory mappings?
Is there a way to query whether a user memory address range is RO, RW, X, ...?
On BSD, POSIX ... systems mmap() and mprotect() can be used to set the memory protections of an address range. So there are 'setters' but what is the associated…

Olsonist
- 2,051
- 1
- 20
- 35
1
vote
1 answer
mprotect errno 22 iOS
I'm developing a jailbroken app on iOS and getting errno 22 when calling
mprotect(p, 1024, PROT_READ | PROT_EXEC)
errno 22 means invalid arguments but I can't figure out whats wrong. I've aligned p to be a multiple of page size, and I've malloced…

Miniroo
- 415
- 5
- 13
1
vote
1 answer
Toggling flags for injected mprotect calls in multi-threaded applications
I am working on a project where a dynamic library (.so) is injected in some target program at runtime (dynamic instrumentation). The library handles its own memory using mmap/munmap. For security reasons, it is required that some mapped region in…

MEE
- 2,114
- 17
- 21
1
vote
1 answer
Solving mprotect() syscall failure
I'm writing some ROP exploit code that calls mprotect via a syscall, after invoking int 0x80 eax is set to 0x0 indicating a success. Shifting execution to the target address still results in a SIGSEGV. I would love for someone to show me where I go…

wireghoul
- 121
- 10
1
vote
1 answer
mprotect : how is memory protection implemented
I already know that mprotect() syscall has 4 protection mode in BSD, but my problem is that how this protection is implemented ( Hardware or Software Implemention ) ?
let's say if we set protection of specific pages to PROT_NONE ,is it really depend…

Payam Mohajeri
- 165
- 1
- 1
- 10
1
vote
1 answer
when will a process need memory pages with both write and exec permissions at once
I'm trying to understand how programs can be isolated and secured.
Are there any valid cases when processes should require PROT_WRITE |PROT_EXEC on a memory page? Can this be avoided?
This seems like the opposite of the things the NX bit or W^X or…

staticd
- 1,194
- 9
- 13
1
vote
2 answers
What is the difference between these alignment functions?
I am writing a self-modifying program; already got it working. I found these two functions, but not sure what EXACTLY they do and I like to comment my code proper.
pagesize is got using getpagesize
/*
* Defining variables:
* func - function in…

Thomas
- 1,401
- 8
- 12
1
vote
5 answers
create member function name and call it at runtime in c++
Can someone give me idea on this problem. I have searched on internet about this, but couldn't get much info as I wished to have.
Say there is a class.
class Foo {
explicit Foo() {}
int getVar1();
int getVar2();
void setVar1(int v);
void…

DeltaVega
- 75
- 1
- 8
1
vote
3 answers
mprotect always returns invalid arguments
I'm trying to modify a value in the .text segment using protect to give me writing access:
int pageSize = sysconf(_SC_PAGE_SIZE);
int *toModify = (int *)(foo+5);
if (mprotect(toModify, pageSize, PROT_WRITE) < 0 ) {
perror("mprotect failed…

arnoapp
- 2,416
- 4
- 38
- 70
1
vote
1 answer
Protect the whole address space using mprotect
For my university project I need to WRITE protect the whole address space of the process. I was reading the /proc/self/maps file and parsing the mapping.
So for each entry of the format 08048000-0804c000 r-xp 00000000 08:03 7971106 /bin/cat, I am…

azizulhakim
- 658
- 7
- 24
1
vote
1 answer
How to protect and unprotect single byte memory?
I know that mprotect is used to protect a whole memory page. Can anyone please tell me if there is a way to protect and unportect a single memory byte?

Muhammad Razib
- 1,297
- 9
- 13
1
vote
0 answers
Detect mprotected memory address
Is there a function to detect whether a given virtual address mapped by mmap is protected by mprotect? Accessing such an address will result in segmentation fault if PROT_NONE is set. So I'd like to first detect whether they're protected or not.…

Cyker
- 9,946
- 8
- 65
- 93