Actually the kernel prevents writing to files which are executed currently
and you can also not execute what is currently open for writing.
That is what VM_DENYWRITE is good for.
Does not work for shared libraries though -- you cannot set VM_DENYWRITE
in user mmap aka ld.so Man page says
MAP_DENYWRITE
This flag is ignored. (Long ago, it signalled that attempts to write to the underlying file should fail
with ETXTBUSY. But this was a source of denial-of-service attacks.)
-Andi
-