From 1096bb8a9e4a54bd9b2b1ce81533490d3ee9ecd0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 24 Dec 2017 18:48:49 +0100 Subject: [PATCH] process-util: allow rename_process() only in the main thread 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 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/basic/process-util.c b/src/basic/process-util.c index f91e2a4..2516730 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -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. */ -- 2.7.4