Skip to content

exec: use systemd AttachProcessesToUnit as a fallback - #2244

Merged
giuseppe merged 1 commit into
containers:mainfrom
kolyshkin:exec-attach-processes
Sep 11, 2026
Merged

giuseppe merged 1 commit into
containers:mainfrom
kolyshkin:exec-attach-processes

Conversation

@kolyshkin

Copy link
Copy Markdown
Collaborator

Moving a process to a cgroup requires write access to cgroup.procs of the common ancestor of the source and the destination cgroups.

This is a problem for a rootless user running crun exec in a login session (e.g. via ssh), when the container is created with the systemd cgroup manager: the session scope is outside of [email protected], so the common ancestor is user-$UID.slice, owned by root. As a result, crun exec fails with:

write to `.../crun-ID.scope/container/cgroup.procs`: Permission denied

In such case, ask systemd to move the process by calling its AttachProcessesToUnit method (which is what runc does). The user systemd instance delegates the operation to the system one when it lacks privileges.

The fallback is only used if writing to cgroup.procs failed with EACCES or EPERM, so the common case is not affected.

Found by the runc integration tests (see #2238), where rootless tests with systemd are run via ssh rootless@localhost.

Moving a process to a cgroup requires write access to cgroup.procs of
the common ancestor of the source and the destination cgroups.

This is a problem for a rootless user running crun exec in a login
session (e.g. via ssh), when the container is created with the systemd
cgroup manager: the session scope is outside of [email protected], so the
common ancestor is user-$UID.slice, owned by root. As a result, crun
exec fails with:

  write to `.../crun-ID.scope/container/cgroup.procs`: Permission denied

In such case, ask systemd to move the process by calling its
AttachProcessesToUnit method (which is what runc does). The user
systemd instance delegates the operation to the system one when it
lacks privileges.

The fallback is only used if writing to cgroup.procs failed with EACCES
or EPERM, so the common case is not affected.

Signed-off-by: Kir Kolyshkin <[email protected]>

@giuseppe giuseppe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@giuseppe
giuseppe merged commit 481408f into containers:main Sep 11, 2026
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants