core: drop ambient capabilities in systemd-executor
Since the commit963b6b906e("core: drop ambient capabilities in user manager") systemd running as the session manager has dropped ambient capabilities retaining other sets allowing user services to be started with elevated capabilities. This, worked fine until the introduction of sd-executor. For a non-root process to be started with elevated capabilities by a non-root parent it either needs file capabilities or ambient capabilities in the parent process. Thus, systemd needs to allow sd-executor to inherit its ambient capabilities and sd-executor should drop them as systemd did before. The ambient set is managed for both system and session managers, but with the default set for PID#1 being empty, this code does not affect operation of PID#1. Fixes:bb5232b6a3("core: add systemd-executor binary")
This commit is contained in:
@@ -466,6 +466,12 @@ int exec_spawn(
|
||||
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
|
||||
dual_timestamp start_timestamp;
|
||||
|
||||
/* Restore the original ambient capability set the manager was started with to pass it to
|
||||
* sd-executor. */
|
||||
r = capability_ambient_set_apply(unit->manager->original_ambient_set, /* also_inherit= */ false);
|
||||
if (r < 0)
|
||||
return log_unit_error_errno(unit, r, "Failed to apply the starting ambient set: %m");
|
||||
|
||||
/* Record the start timestamp before we fork so that it is guaranteed to be earlier than the
|
||||
* handoff timestamp. */
|
||||
dual_timestamp_now(&start_timestamp);
|
||||
@@ -480,6 +486,10 @@ int exec_spawn(
|
||||
environ,
|
||||
cg_unified() > 0 ? subcgroup_path : NULL,
|
||||
&pidref);
|
||||
|
||||
/* Drop the ambient set again, so no processes other than sd-executore spawned from the manager inherit it. */
|
||||
(void) capability_ambient_set_apply(0, /* also_inherit= */ false);
|
||||
|
||||
if (r == -EUCLEAN && subcgroup_path)
|
||||
return log_unit_error_errno(unit, r,
|
||||
"Failed to spawn process into cgroup '%s', because the cgroup "
|
||||
|
||||
Reference in New Issue
Block a user