diff options
author | Mike Yuan <me@yhndnzj.com> | 2024-11-20 15:11:03 +0100 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2024-11-20 19:10:26 +0100 |
commit | f87863a8ffe4c08a6face2e43a62d7852978642a (patch) | |
tree | 1ab09880285706100740d783926b576f2d7c94e1 | |
parent | cryptenroll: fix typo (diff) | |
download | systemd-f87863a8ffe4c08a6face2e43a62d7852978642a.tar.xz systemd-f87863a8ffe4c08a6face2e43a62d7852978642a.zip |
process-util: refuse to operate on remote PidRef
Follow-up for 7e3e540b88db5546d0c63103619d96b033871b7b
-rw-r--r-- | src/basic/process-util.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/basic/process-util.c b/src/basic/process-util.c index adc576a84f..3253a9c3fb 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -102,8 +102,8 @@ int pid_get_comm(pid_t pid, char **ret) { _cleanup_free_ char *escaped = NULL, *comm = NULL; int r; - assert(ret); assert(pid >= 0); + assert(ret); if (pid == 0 || pid == getpid_cached()) { comm = new0(char, TASK_COMM_LEN + 1); /* Must fit in 16 byte according to prctl(2) */ @@ -143,6 +143,9 @@ int pidref_get_comm(const PidRef *pid, char **ret) { if (!pidref_is_set(pid)) return -ESRCH; + if (pidref_is_remote(pid)) + return -EREMOTE; + r = pid_get_comm(pid->pid, &comm); if (r < 0) return r; @@ -289,6 +292,9 @@ int pidref_get_cmdline(const PidRef *pid, size_t max_columns, ProcessCmdlineFlag if (!pidref_is_set(pid)) return -ESRCH; + if (pidref_is_remote(pid)) + return -EREMOTE; + r = pid_get_cmdline(pid->pid, max_columns, flags, &s); if (r < 0) return r; @@ -331,6 +337,9 @@ int pidref_get_cmdline_strv(const PidRef *pid, ProcessCmdlineFlags flags, char * if (!pidref_is_set(pid)) return -ESRCH; + if (pidref_is_remote(pid)) + return -EREMOTE; + r = pid_get_cmdline_strv(pid->pid, flags, &args); if (r < 0) return r; @@ -477,6 +486,9 @@ int pidref_is_kernel_thread(const PidRef *pid) { if (!pidref_is_set(pid)) return -ESRCH; + if (pidref_is_remote(pid)) + return -EREMOTE; + result = pid_is_kernel_thread(pid->pid); if (result < 0) return result; @@ -594,6 +606,9 @@ int pidref_get_uid(const PidRef *pid, uid_t *ret) { if (!pidref_is_set(pid)) return -ESRCH; + if (pidref_is_remote(pid)) + return -EREMOTE; + r = pid_get_uid(pid->pid, &uid); if (r < 0) return r; @@ -794,6 +809,9 @@ int pidref_get_start_time(const PidRef *pid, usec_t *ret) { if (!pidref_is_set(pid)) return -ESRCH; + if (pidref_is_remote(pid)) + return -EREMOTE; + r = pid_get_start_time(pid->pid, ret ? &t : NULL); if (r < 0) return r; @@ -1093,6 +1111,9 @@ int pidref_is_my_child(const PidRef *pid) { if (!pidref_is_set(pid)) return -ESRCH; + if (pidref_is_remote(pid)) + return -EREMOTE; + result = pid_is_my_child(pid->pid); if (result < 0) return result; @@ -1128,6 +1149,9 @@ int pidref_is_unwaited(const PidRef *pid) { if (!pidref_is_set(pid)) return -ESRCH; + if (pidref_is_remote(pid)) + return -EREMOTE; + if (pid->pid == 1 || pidref_is_self(pid)) return true; @@ -1169,6 +1193,9 @@ int pidref_is_alive(const PidRef *pidref) { if (!pidref_is_set(pidref)) return -ESRCH; + if (pidref_is_remote(pidref)) + return -EREMOTE; + result = pid_is_alive(pidref->pid); if (result < 0) { assert(result != -ESRCH); |