Skip to content

Commit e03c12c

Browse files
WOnder93pcmoore
authored andcommitted
selinux-testsuite: Add minimal test for cgroupfs label inheritance
This patch adds a tiny test that checks that labels of newly created cgroupfs files/directories are correctly inherited from the parent. Should start passing when the following issue is fixed: SELinuxProject/selinux-kernel#39 Signed-off-by: Ondrej Mosnacek <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent f337782 commit e03c12c

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

policy/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ TARGETS = \
2525
test_task_getsid.te test_task_setpgid.te test_task_setsched.te \
2626
test_transition.te test_inet_socket.te test_unix_socket.te \
2727
test_mmap.te test_overlayfs.te test_mqueue.te test_mac_admin.te \
28-
test_ibpkey.te test_atsecure.te
28+
test_ibpkey.te test_atsecure.te test_cgroupfs.te
2929

3030
ifeq ($(shell [ $(POL_VERS) -ge 24 ] && echo true),true)
3131
TARGETS += test_bounds.te

policy/test_cgroupfs.te

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#################################
2+
#
3+
# Policy for testing cgroupfs labeling
4+
#
5+
6+
# Types for test file.
7+
type test_cgroup_t;
8+
files_type(test_cgroup_t)
9+
10+
require {
11+
type cgroup_t;
12+
}
13+
allow test_cgroup_t cgroup_t:filesystem { associate };

tests/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ SUBDIRS:= domain_trans entrypoint execshare exectrace execute_no_trans \
1111
task_setnice task_setscheduler task_getscheduler task_getsid \
1212
task_getpgid task_setpgid file ioctl capable_file capable_net \
1313
capable_sys dyntrans dyntrace bounds nnp_nosuid mmap unix_socket \
14-
inet_socket overlay checkreqprot mqueue mac_admin atsecure
14+
inet_socket overlay checkreqprot mqueue mac_admin atsecure \
15+
cgroupfs_label
1516

1617
ifeq ($(shell grep -q cap_userns $(POLDEV)/include/support/all_perms.spt && echo true),true)
1718
ifneq ($(shell ./kvercmp $$(uname -r) 4.7),-1)

tests/cgroupfs_label/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
all:
2+
clean:

tests/cgroupfs_label/test

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/perl
2+
3+
use Test;
4+
BEGIN { plan tests => 2 }
5+
6+
my $ret;
7+
8+
# Create a new cgroupfs directory and relabel it.
9+
mkdir("/sys/fs/cgroup/unified/test");
10+
system("chcon -R -t test_cgroup_t /sys/fs/cgroup/unified/test");
11+
12+
# Create a subdirectory in it.
13+
mkdir("/sys/fs/cgroup/unified/test/subdir");
14+
15+
$ret =
16+
system("test `secon -tf /sys/fs/cgroup/unified/test/subdir` = test_cgroup_t");
17+
ok( $ret, 0 ); # Did the subdirectory inherit the parent's label?
18+
19+
$ret = system(
20+
"test `secon -tf /sys/fs/cgroup/unified/test/subdir/cgroup.type` = test_cgroup_t"
21+
);
22+
ok( $ret, 0 ); # Did also files in the subdirectory inherit the label?
23+
24+
# Cleanup.
25+
rmdir("/sys/fs/cgroup/unified/test/subdir");
26+
rmdir("/sys/fs/cgroup/unified/test");
27+
28+
exit;

0 commit comments

Comments
 (0)