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)
committerLennart Poettering <lennart@poettering.net>
Mon, 25 Dec 2017 10:48:21 +0000 (11:48 +0100)
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 f91e2a4..2516730 100644 (file)
@@ -297,6 +297,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. */