13 ms·
I assume he's talking about: prctl(PR_SET_MM, PR_SET_MM_EXE_FILE, fd, 0, 0) Regarding the munmapping stuff, if you read the code for "replace_mm_exe_file"
by TheDong 2y ago
I assume he's talking about:
prctl(PR_SET_MM, PR_SET_MM_EXE_FILE, fd, 0, 0)
Regarding the munmapping stuff, if you read the code for "replace_mm_exe_file" in the kernel source code, it should make sense.
- matheusmoreira 2y agoThanks for the pointers!! https://www.man7.org/linux/man-pages/man2/PR_SET_MM_EXE_FILE.2const.html https://www.man7.org/linux/man-pages/man2/PR_SET_MM_EXE_FILE... https://github.com/torvalds/linux/blob/master/kernel/fork.c#L1431 https://github.com/torvalds/linux/blob/master/kernel/fork.c#... /* Forbid mm->exe_file change if old file still mapped. */ I suppose before doing this the process must copy its own process image to another location and jump there. Otherwise it will end up crashing due to segmentation violation when the next instructions are fetched by the processor since the code is no longer in memory. Linux passes the process a pointer to the program header table via the auxiliary vector. Given that pointer it's possible to reach every page in the process's memory image¸ and likely also the ELF header itself. I suppose it's just a matter of mapping in new pages, copying all the data over and unmapping the original ones. Maybe Linux should keep a copy of the process's initial state and expose that in procfs as well.