Having the following pseudocode executed by a superuser, is it safe to assume that it is secure on Linux?
if fork() == 0:
# drop privileges to an unprivileged user, let's say "nobody"
# perform various tasks, start other processes as "nobody"
# communicate with parent process through unsafe means, e.g. Python pickle
Now, Pickle is known to be susceptible to RCE if the data to be unpickled comes from an untrusted source. Although I assume my own code to be free of vulnerabilities, my concern is that the above code could still be vulnerable to privilege escalation through another process running as "nobody" that tampers with the memory of the unprivileged fork. If "nobody" could tamper with the memory of the process, it could potentially inject a pickled object which then leads to remote code execution in the parent process, i.e. as root user, which would be a privilege escalation. On the systems I tested this on, e.g. through writing to /proc/$pid/mem
, I was able to tamper with the memory of another process only as superuser. However, I prefer to not just rely on a few tests on Linux machines where the behavior could depend on the distribution/configuration.
So my question is: Is this code secure? If so, where can I find a documentation guaranteeing that this behavior is universally secure? Alternatively, is there an argument that shows that a system would be inherently unsafe if it allowed an unprivileged user to tamper with all other processes running under their user id?
A question on how to implement secure child-to-parent communication in a setting where the child drops permissions has already been asked on Stackoverflow and since the accepted answer uses pickling under the hood, my question boils down to whether this approach is really secure.
python
process launched by yourself, within the same context as a malicious one, on the 'average' linux kernel, any more than you can punch yourself in the face and win... (eg. trystrace
next time you startpython
and see how much gets pulled in...) Q: do you have the luxury of signing or encrypting (aead) the pickled data?python
process can produce the pickle, and in the future, you can validate the integrity before you trust it .. but can you do this for all.so
or.pyc
? as you already know, nothing will stop an adjacent process in the current context from potentially accessing memory, the risk here being that another process intercepts the secret signing key, and generates a trustworthy sig for a malicious xyz file (look athidepid=2
viz. linux-dev.org/2012/09/hide-process-information-for-other-users)