previous: >>107841306#define __NR_mprotect 10this guy is pretty similar to mmap in a lot of ways, with the obvious difference being that mprotect only lets you change the protections of mappings which already exist.since we didn't talk about SIGSEGV much in the last thread, perhaps that could be the focus of this one?relevant resources: man manman syscallshttps://man7.org/linux/man-pages/https://linux.die.net/man/https://elixir.bootlin.com/linux/https://elixir.bootlin.com/musl/https://elixir.bootlin.com/glibc/
#define __NR_mprotect 10
man man
man syscalls
i'll give it a bmup
>>107851217What's an example usage of mprotect? I understand why the kernel would need to be able to set permissions on pages, but why would this need to be done at the user level?Maybe if you want to do something with a JIT? You could dump machine code straight into RAM and mark the pages as executable. I don't think mprotect really does much for security, because your code can just call it anytime. Maybe if you have a virtual environment in your program that you can enter and exit, then it can be helpful for security? You'd need to male sure that the virtual environment can never call mprotect.
>>107853273Usually there's a forbidden page just past the end of stack memory so that you crash in case of a stack overflow. This sort of thing isn't airtight but it can be very helpful.I think it tends to be a mitigation, something that hopefully prevents bad consequences once something else has gone wrong.