summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-11-20 12:02:46 +0100
committerLuca Boccassi <luca.boccassi@gmail.com>2024-11-20 19:11:38 +0100
commitf6793bbcf0e3f0a6daa77add96183b88d5ec2117 (patch)
tree27d962cbc7eeb05011da11681a2fc350ad78348e /src/shared
parentprocess-util: refuse to operate on remote PidRef (diff)
downloadsystemd-f6793bbcf0e3f0a6daa77add96183b88d5ec2117.tar.xz
systemd-f6793bbcf0e3f0a6daa77add96183b88d5ec2117.zip
killall: gracefully handle processes inserted into containers via nsenter -a
"nsenter -a" doesn't migrate the specified process into the target cgroup (it really should). Thus the cgroup will remain in a cgroup that is (due to cgroup ns) outside our visibility. The kernel will report the cgroup path of such cgroups as starting with "/../". Detect that and print a reasonably error message instead of trying to resolve that.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/killall.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/shared/killall.c b/src/shared/killall.c
index a08736480e..184aec018b 100644
--- a/src/shared/killall.c
+++ b/src/shared/killall.c
@@ -46,13 +46,17 @@ static bool argv_has_at(pid_t pid) {
return c == '@';
}
-static bool is_survivor_cgroup(const PidRef *pid) {
+static bool is_in_survivor_cgroup(const PidRef *pid) {
_cleanup_free_ char *cgroup_path = NULL;
int r;
assert(pidref_is_set(pid));
r = cg_pidref_get_path(/* root= */ NULL, pid, &cgroup_path);
+ if (r == -EUNATCH) {
+ log_warning_errno(r, "Process " PID_FMT " appears to originate in foreign namespace, ignoring.", pid->pid);
+ return true;
+ }
if (r < 0) {
log_warning_errno(r, "Failed to get cgroup path of process " PID_FMT ", ignoring: %m", pid->pid);
return false;
@@ -86,7 +90,7 @@ static bool ignore_proc(const PidRef *pid, bool warn_rootfs) {
return true; /* also ignore processes where we can't determine this */
/* Ignore processes that are part of a cgroup marked with the user.survive_final_kill_signal xattr */
- if (is_survivor_cgroup(pid))
+ if (is_in_survivor_cgroup(pid))
return true;
r = pidref_get_uid(pid, &uid);