File tree Expand file tree Collapse file tree 3 files changed +58
-3
lines changed Expand file tree Collapse file tree 3 files changed +58
-3
lines changed Original file line number Diff line number Diff line change @@ -175,6 +175,10 @@ ifeq ($(shell grep -q user_namespace $(POLDEV)/include/support/all_perms.spt &&
175175export M4PARAM += -Duser_namespace_defined
176176endif
177177
178+ ifeq ($(shell grep -q checkpoint_restore $(POLDEV ) /include/support/all_perms.spt && echo true) ,true)
179+ export M4PARAM += -Dcheckpoint_restore_defined
180+ endif
181+
178182# conditional xperm dependency: policy >= 34
179183ifeq ($(shell [ $(POL_VERS ) -ge 34 -a $(MAX_KERNEL_POLICY ) -ge 34 ] && echo true) ,true)
180184TARGETS += test_ioctl_cond_xperms.te
Original file line number Diff line number Diff line change 44#
55
66attribute capusernsdomain;
7+ attribute cap2 usernsdomain;
78
89# Domain for process that is allowed non-init userns capabilities
910type test_cap_userns_t;
@@ -22,3 +23,23 @@ typeattribute test_no_cap_userns_t capusernsdomain;
2223allow_userns_create(capusernsdomain)
2324# linux >= v5.12 needs setfcap to map UID 0
2425allow capusernsdomain self:capability setfcap;
26+
27+ # Domain for process that is allowed to use cap_checkpoint_restore
28+ type test_cap2 _userns_t;
29+ testsuite_domain_type(test_cap2 _userns_t)
30+ typeattribute test_cap2 _userns_t cap2 usernsdomain;
31+ ifdef(`checkpoint_restore_defined', `
32+ allow test_cap2 _userns_t self:cap2 _userns checkpoint_restore;
33+ ')
34+
35+ # Domain for process that is not to use cap_checkpoint_restore
36+ type test_no_cap2 _userns_t;
37+ testsuite_domain_type(test_no_cap2 _userns_t)
38+ typeattribute test_no_cap2 _userns_t cap2 usernsdomain;
39+
40+ # Rules common to both domains.
41+ ifdef(`kernel_rw_kernel_ns_lastpid_sysctl',`
42+ kernel_rw_kernel_ns_lastpid_sysctl(cap2 usernsdomain)
43+ ', `
44+ kernel_rw_kernel_sysctl(cap2 usernsdomain)
45+ ')
Original file line number Diff line number Diff line change @@ -6,15 +6,28 @@ BEGIN {
66 $basedir = $0 ;
77 $basedir =~ s | (.*)/[^/]*| $1 | ;
88
9+ $test_checkpoint = 0;
10+
911 if ( -e ' /proc/sys/kernel/unprivileged_userns_clone' ) {
1012 system (
1113 " echo 1 > /proc/sys/kernel/unprivileged_userns_clone 2> /dev/null" );
1214 }
13- if ( system (" $basedir /userns_child_exec -t -U > /dev/null 2>&1" ) = = 0 ) {
14- plan tests => 2 ;
15+ if ( system (" $basedir /userns_child_exec -t -U > /dev/null 2>&1" ) ! = 0 ) {
16+ plan skip_all => " CLONE_NEWUSER not supported " ;
1517 }
1618 else {
17- plan skip_all => " CLONE_NEWUSER not supported" ;
19+ $test_count = 2;
20+
21+ # CAP_CHECKPOINT_RESTORE is supported since 5.9
22+ $kvercur = ` uname -r` ;
23+ chomp ($kvercur );
24+
25+ if ( ` $basedir /../kvercmp $kvercur 5.9` > 0 ) {
26+ $test_checkpoint = 1;
27+ $test_count += 2;
28+ }
29+
30+ plan tests => $test_count ;
1831 }
1932}
2033
@@ -32,6 +45,23 @@ $result = system(
3245);
3346ok($result );
3447
48+ if ($test_checkpoint ) {
49+
50+ # Verify that test_cap2_userns_t can use cap_checkpoint_restore
51+
52+ $result = system (
53+ " $basedir /userns_child_exec -p -U -M '0 0 1' -G '0 0 1' -- runcon -t test_cap2_userns_t -- sh -c 'echo 1000 > /proc/sys/kernel/ns_last_pid' 2>&1"
54+ );
55+ ok( $result eq 0 );
56+
57+ # Verify that test_no_cap_userns_t cannot use cap_checkpoint_restore
58+
59+ $result = system (
60+ " $basedir /userns_child_exec -p -U -M '0 0 1' -G '0 0 1' -- runcon -t test_no_cap2_userns_t -- sh -c 'echo 1000 > /proc/sys/kernel/ns_last_pid' 2>&1"
61+ );
62+ ok($result );
63+ }
64+
3565if ( -e ' /proc/sys/kernel/unprivileged_userns_clone' ) {
3666 system (" echo 0 > /proc/sys/kernel/unprivileged_userns_clone 2> /dev/null" );
3767}
You can’t perform that action at this time.
0 commit comments