Skip to content

Commit d9ed29d

Browse files
committed
Add test for attribute assignment to attributes
Replicate two tests, but all access (including assignment to attributes like domain) is assigned via proxy attributes -- attributes are used in place of the original types and types used in the tests are assigned to the proxy attributes (no access is assigned directly to the types). The following checkpolicy patch is needed to compile the test policy: https://lore.kernel.org/selinux/20250623102726.3818713-1-vmojzis@redhat.com/ Checkpolicy builds with the patch applied are available in: https://copr.fedorainfracloud.org/coprs/vmojzis/userspace_test/ TODO: the test needs to be made conditional on userspace version Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
1 parent 72e60b6 commit d9ed29d

File tree

7 files changed

+149
-2
lines changed

7 files changed

+149
-2
lines changed

policy/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ TARGETS = \
2929
test_task_getsid.te test_task_setpgid.te test_task_setsched.te \
3030
test_transition.te test_unix_socket.te \
3131
test_mmap.te test_overlayfs.te test_mqueue.te \
32-
test_ibpkey.te test_atsecure.te test_cgroupfs.te
32+
test_ibpkey.te test_atsecure.te test_cgroupfs.te \
33+
test_attribute_assignment.te
3334

3435
ifeq (x$(DISTRO),$(filter x$(DISTRO),xRHEL4 xRHEL5 xRHEL6))
3536
SUPPORTS_CIL = n
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
##########################################
2+
#
3+
# Policy for testing attribute assignment to attributes
4+
#
5+
6+
# 4 attributtes linked in a typeattribute sequence d->c->b->a
7+
attribute test_attribute_a;
8+
attribute test_attribute_b;
9+
attribute test_attribute_c;
10+
attribute test_attribute_d;
11+
12+
typeattribute test_attribute_b test_attribute_a;
13+
typeattribute test_attribute_c test_attribute_b;
14+
typeattribute test_attribute_d test_attribute_c;
15+
16+
# 2 types assigned to attributes b and d
17+
type test_attribute_setpgid_yes_t;
18+
type test_attribute_setpgid_no_t;
19+
20+
typeattribute test_attribute_setpgid_no_t test_attribute_b;
21+
typeattribute test_attribute_setpgid_yes_t test_attribute_d;
22+
23+
# Attribute "a" is made into a minimal domain type
24+
testsuite_domain_type_minimal(test_attribute_a)
25+
# Attribute "c" and types assigned to it can change its pgid
26+
testsuite_domain_type(test_attribute_c)
27+
28+
# Allow each attribute some access so that they don't get optimized out
29+
allow test_attribute_a test_attribute_a:dir getattr;
30+
allow test_attribute_b test_attribute_b:dir getattr;
31+
allow test_attribute_c test_attribute_c:dir getattr;
32+
allow test_attribute_d test_attribute_d:dir getattr;
33+
34+
##########################################
35+
#
36+
# repeats entrypoint test, only with attributes as proxies for every type
37+
#
38+
39+
# Type that the test domain can be entered through
40+
attribute test_attribute_entrypoint;
41+
files_type(test_attribute_entrypoint)
42+
43+
# Type that the test domain can NOT be entered through
44+
attribute test_attribute_entrypoint_deny;
45+
files_type(test_attribute_entrypoint_deny)
46+
47+
# Test domain that can only be entered via test_attribute_entrypoint
48+
attribute test_attribute_domain;
49+
testsuite_domain_type(test_attribute_domain)
50+
51+
# Allow test_attribute_domain to be entered via test_attribute_entrypoint.
52+
domain_entry_file(test_attribute_domain, test_attribute_entrypoint)
53+
54+
# Allow test_attribute_domain to execute test_attribute_entrypoint_deny, but not
55+
# to enter through it
56+
can_exec(test_attribute_domain, test_entrypoint_deny_t)
57+
58+
# assign corresponding types
59+
type test_attribute_entrypoint_t;
60+
typeattribute test_attribute_entrypoint_t test_attribute_entrypoint;
61+
62+
type test_attribute_entrypoint_deny_t;
63+
typeattribute test_attribute_entrypoint_deny_t test_attribute_entrypoint_deny;
64+
65+
type test_attribute_domain_t;
66+
typeattribute test_attribute_domain_t test_attribute_domain;
67+

tests/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ SUBDIRS:= domain_trans entrypoint execshare exectrace execute_no_trans \
2828
task_getpgid task_setpgid file ioctl capable_file capable_net \
2929
capable_sys dyntrans dyntrace bounds nnp_nosuid mmap unix_socket \
3030
inet_socket/tcp inet_socket/udp overlay checkreqprot mqueue \
31-
mac_admin atsecure infiniband_endport infiniband_pkey
31+
mac_admin atsecure infiniband_endport infiniband_pkey \
32+
attribute_assignment
3233

3334
ifeq ($(shell grep -q cap_userns $(POLDEV)/include/support/all_perms.spt && echo true),true)
3435
ifneq ($(shell ./kvercmp $$(uname -r) 4.7),-1)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
TARGETS=source
2+
3+
all: $(TARGETS)
4+
clean:
5+
rm -f $(TARGETS)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef _GNU_SOURCE
2+
#define _GNU_SOURCE
3+
#endif
4+
#include <stdio.h>
5+
#include <sys/types.h>
6+
#include <unistd.h>
7+
#include <stdlib.h>
8+
9+
int main(void)
10+
{
11+
pid_t pid, group_id;
12+
13+
pid = getpid();
14+
if ((group_id = getpgid(pid)) < 0) {
15+
perror("getpgid");
16+
exit(-1);
17+
}
18+
printf("Group ID = %d\n", group_id);
19+
if (setpgid(pid, pid) < 0) {
20+
perror("setpgid");
21+
exit(1);
22+
}
23+
if ((group_id = getpgid(pid)) < 0) {
24+
perror("getpgid");
25+
exit(-1);
26+
}
27+
printf("Group ID = %d\n", group_id);
28+
printf("pid = %d\n", pid);
29+
exit(0);
30+
}

tests/attribute_assignment/test

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/perl
2+
3+
use Test;
4+
BEGIN { plan tests => 4 }
5+
6+
# task_getpgid, but all permissions are assigned using attributes (two step transition)
7+
8+
$basedir = $0;
9+
$basedir =~ s|(.*)/[^/]*|$1|;
10+
11+
# Verify that test_setpgid_yes_t can setpgid.
12+
$result =
13+
system("runcon -t test_attribute_setpgid_yes_t -- $basedir/source 2>&1");
14+
ok( $result, 0 );
15+
16+
# Verify that test_setpgid_no_t cannot setpgid.
17+
$result =
18+
system("runcon -t test_attribute_setpgid_no_t -- $basedir/source 2>&1");
19+
ok($result);
20+
21+
# entrypoint test, but all permissions are passed using attributes
22+
23+
$basedir = $0;
24+
$basedir =~ s|(.*)/[^/]*|$1|;
25+
26+
system("cp /bin/true $basedir/true");
27+
28+
# Verify that test_attribute_domain_t cannot be entered via test_attribute_entrypoint_deny_t.
29+
system("chcon -t test_attribute_entrypoint_deny_t $basedir/true");
30+
$result = system("runcon -t test_attribute_domain_t $basedir/true 2>&1");
31+
ok($result); #this should fail
32+
33+
# Verify that test_attribute_domain_t can be entered via test_attribute_entrypoint_t.
34+
system("chcon -t test_attribute_entrypoint_t $basedir/true");
35+
$result = system("runcon -t test_attribute_domain_t $basedir/true");
36+
ok( $result, 0 ); #this should pass
37+
38+
# Cleanup.
39+
system("rm -f $basedir/true");
40+
41+
exit;
42+

0 commit comments

Comments
 (0)