mirror of
https://github.com/systemd/systemd.git
synced 2025-03-03 16:58:37 +03:00
test: add testcase that verifies we can safely delete subcgroups owned by other users if we own the parent
This is a test for the previous commits: we create an unpriv, delegated cgroup in --user mode, then create a subcgroup that is owned by some other user (to mimic the case where an unpriv user got a userns with delegated UIDs assigned), and then try to stop the unit. traditionally this would fail, because our unpriv systemd --user instance can't remove the subcrroup owned by someone else. With the earlier patches this is addressed.
This commit is contained in:
parent
51a70c8875
commit
1d5fd2e621
@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
# shellcheck disable=SC2235
|
||||
set -eux
|
||||
set -o pipefail
|
||||
|
||||
@ -87,6 +88,39 @@ testcase_scope_unpriv_delegation() {
|
||||
-w /sys/fs/cgroup/workload.slice/test-workload0.scope/cgroup.subtree_control
|
||||
}
|
||||
|
||||
testcase_user_unpriv_delegation() {
|
||||
# Check that delegation works for unpriv users, and that we can insert a
|
||||
# subcgroup owned by a different user (which can happen in case unpriv
|
||||
# userns where a UID range was delegated), which is still cleaned up
|
||||
# correctly when it goes down.
|
||||
|
||||
run0 -u testuser systemd-run --user \
|
||||
--property="Delegate=yes" \
|
||||
--unit=test-chown-subcgroup \
|
||||
--service-type=exec \
|
||||
sleep infinity
|
||||
|
||||
TESTUID=$(id -u testuser)
|
||||
CGROUP="/sys/fs/cgroup/user.slice/user-$TESTUID.slice/user@$TESTUID.service/app.slice/test-chown-subcgroup.service"
|
||||
test -d "$CGROUP"
|
||||
|
||||
# Create a subcgroup, and make it owned by some unrelated user
|
||||
SUBCGROUP="$CGROUP/subcgroup"
|
||||
mkdir "$SUBCGROUP"
|
||||
chown 1:1 "$SUBCGROUP"
|
||||
|
||||
# Make sure the subcgroup is not empty (empty dirs owned by other users can
|
||||
# be removed if one owns the dir they are contained in, after all)
|
||||
mkdir "$SUBCGROUP"/filler
|
||||
|
||||
run0 -u testuser systemctl stop --user test-chown-subcgroup.service
|
||||
|
||||
# Verify that the subcgroup got correctly removed
|
||||
(! test -e "$CGROUP")
|
||||
|
||||
systemctl stop user@testuser.service
|
||||
}
|
||||
|
||||
testcase_subgroup() {
|
||||
# Verify that DelegateSubgroup= affects ownership correctly
|
||||
unit="test-subgroup-$RANDOM.service"
|
||||
|
Loading…
x
Reference in New Issue
Block a user