WIP: tests: Add cap2_userns checkpoint_restore test#100
Closed
bachradsusi wants to merge 2 commits intoSELinuxProject:mainfrom
Closed
WIP: tests: Add cap2_userns checkpoint_restore test#100bachradsusi wants to merge 2 commits intoSELinuxProject:mainfrom
bachradsusi wants to merge 2 commits intoSELinuxProject:mainfrom
Conversation
Sometimes it's useful to know how a child ended. Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
d3ea0a9 to
2af8524
Compare
Member
|
Actually, you can avoid using diff --git a/policy/test_cap_userns.te b/policy/test_cap_userns.te
index 11febae..402675b 100644
--- a/policy/test_cap_userns.te
+++ b/policy/test_cap_userns.te
@@ -27,21 +27,13 @@ allow capusernsdomain self:capability setfcap;
# Domain for process that is allowed to use cap_checkpoint_restore
type test_cap2_userns_t;
testsuite_domain_type(test_cap2_userns_t)
-typeattribute test_cap2_userns_t capusernsdomain;
typeattribute test_cap2_userns_t cap2usernsdomain;
allow test_cap2_userns_t self:cap2_userns checkpoint_restore;
# Domain for process that is not to use cap_checkpoint_restore
type test_no_cap2_userns_t;
testsuite_domain_type(test_no_cap2_userns_t)
-typeattribute test_no_cap2_userns_t capusernsdomain;
typeattribute test_no_cap2_userns_t cap2usernsdomain;
# Rules common to both domains.
-allow_userns_create(cap2usernsdomain)
-# linux >= v5.12 needs setfcap to map UID 0
-allow cap2usernsdomain self:capability setfcap;
-
-allow cap2usernsdomain self:cap_userns setpcap;
-allow cap2usernsdomain self:cap_userns sys_admin;
kernel_rw_kernel_ns_lastpid_sysctl(cap2usernsdomain)
diff --git a/tests/cap_userns/test b/tests/cap_userns/test
index f976889..9cee33d 100755
--- a/tests/cap_userns/test
+++ b/tests/cap_userns/test
@@ -35,14 +35,14 @@ ok($result);
# Verify that test_cap2_userns_t can use cap_checkpoint_restore
$result = system(
-"runcon -t test_cap2_userns_t -- $basedir/userns_child_exec -p -U -M '0 0 1' -G '0 0 1' -- capsh --drop=cap_sys_admin -+ -c 'echo 1000 > /proc/sys/kernel/ns_last_pid' 2>&1"
+"$basedir/userns_child_exec -p -U -M '0 0 1' -G '0 0 1' -- runcon -t test_cap2_userns_t -- sysctl -w kernel.ns_last_pid=1000 2>&1"
);
ok( $result eq 0 );
# Verify that test_no_cap_userns_t cannot use cap_checkpoint_restore
$result = system(
-"runcon -t test_no_cap2_userns_t -- $basedir/userns_child_exec -p -U -M '0 0 1' -G '0 0 1' -- capsh --drop=cap_sys_admin -+ -c 'echo 1000 > /proc/sys/kernel/ns_last_pid' 2>&1"
+"$basedir/userns_child_exec -p -U -M '0 0 1' -G '0 0 1' -- runcon -t test_no_cap2_userns_t -- sysctl -w kernel.ns_last_pid=1000 2>&1"
);
ok($result);
|
According to pid_namespaces(7) CAP_CHECK_RESTORE is required to write to /proc/sys/kernel/ns_last_pid Check whether a process in user and pid namespace is able to write there when it has cap2_userns checkpoint_restore allowed. Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
2af8524 to
48afaf3
Compare
Member
Author
|
Updated based on your comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Create a child process in new pid and user namespaces and drop CAP_SYS_ADMIN to enforce using CAP_CHECKPOINT_RESTORE capability which is required for writing to /proc/sys/kernel/ns_last_pid