Are reads of /proc/pid/environ atomic in Linux 6.x (e.g: 6.1.99)?
0
votes
1
answer
47
views
When a process execs, looking at kernel code for environ_read(), it seems that if the mm_struct doesn't yet exist / is null or the env_end member of that mm_struct is null, environ_read() will return 0 ~immediately.
My question is, are there protections WRT fork/exec races such that (pseudo-code ahead)
if ((pid = fork) != 0)
execv*("/bin/exe", {"exe", "-l"}, &envp)
read("/proc/${pid}/environ")
Cannot:
**A:** erroneously read a zero-length env due to races with execve and the subsequent read (e.g: assuming the user space program that issues the read is multi-threaded or performing asynchronous IO)
**B:** erroneously read a partial env (assuming user-space code is not causing a short read due to a bug in user space code)
**C:** erroneously read the parent's env
Are reads from /p/p/environ atomic?
Asked by Gregg Leventhal
(109 rep)
Nov 3, 2024, 02:51 PM
Last activity: Nov 19, 2024, 02:23 PM
Last activity: Nov 19, 2024, 02:23 PM