chiark / gitweb /
process-util: allow rename_process() only in the main thread
authorLennart Poettering <lennart@poettering.net>
Sun, 24 Dec 2017 17:48:49 +0000 (18:48 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:49:45 +0000 (07:49 +0200)
We make assumptions about the comm name we set via PR_SET_NAME: that it
would reflect the process name, but that's only the case for the main
thread. Moreover, we cache the mmap() region without locking.

Let's hence be safe rather than sorry and support all this only in the
main thread.

src/basic/process-util.c

index e1b2664f3dad53e00dde1899edbd5c6447f219e3..5a00fca834ff1b05931702eb86c7963b5ad13596 100644 (file)
@@ -298,6 +298,11 @@ int rename_process(const char name[]) {
         if (isempty(name))
                 return -EINVAL; /* let's not confuse users unnecessarily with an empty name */
 
+        if (!is_main_thread())
+                return -EPERM; /* Let's not allow setting the process name from other threads than the main one, as we
+                                * cache things without locking, and we make assumptions that PR_SET_NAME sets the
+                                * process name that isn't correct on any other threads */
+
         l = strlen(name);
 
         /* First step, change the comm field. */