Re: Statically allocated guard pages in ELF
Taylor R Campbell <[email protected]> Sat, 29 Mar 2025 02:12:41 +0000
| Newsgroups | gmane.os.netbsd.devel.toolchain |
|---|---|
| Message-ID | <[email protected]> |
> Date: Fri, 28 Mar 2025 19:30:55 +0000 > From: Taylor R Campbell <[email protected]> > > Setting aside the copied & pasted mmap/mprotect logic across three > files, I'm not entirely happy with the patch because it adds several > mmap/mprotect calls to every program startup in libc. > > Can it be done with an ELF trick to request a guard page instead, so > there's no additional syscall overhead but the kernel sets up a > PROT_NONE page before each table it already maps from the file? On reflection, I realize this is a fool's errand because the LOAD commands _in a shared library_ like libc.so are executed by rtld by calling mmap/mprotect, so nothing can be saved by this ELF magic. (For a static executable -- or the rtld interpreter itself -- the kernel will execute the LOAD commands, possibly with lower overhead than mmap/mprotect syscalls, but that's the only case that this could improve.)