2 ms·
Thanks 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
by matheusmoreira 2y ago
Thanks 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.