According to this thread,memory allocated by malloc
at least have PROT_READ | PROT_EXEC
,otherwise the contaned function can't be executed .
man malloc
doesn't mention anything about protection thus the question.
malloc
is not the right tool for allocating memory for code. You should use mmap
, and depending on the paranoid security policies on your system, you might need to use mprotect
too for changing the permissions.
Among the reasons malloc
is not the right tool:
malloc
is unlikely to be page-aligned, and thus you'll end up setting permissions on adjacent memory too, possibly breaking things.free
, you might break malloc
's internals.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With