Skip to contentSkip to conversation

Prepare userfaultfd policy for Fedora policy changes

PATCH In review Ondrej Mosnacek 2 participants 6 messages Aug 24, 2022 – Aug 26, 2022 SELinux security module

lore
Share & tools
lore
#0 lore raw

cover Prepare userfaultfd policy for Fedora policy changes

See the description of the second patch for explanation. While there, the first patch cleans up the userfaultfd policy to be in just one file, since the CIL workaround is no longer needed.

Ondrej Mosnacek (2):
policy: remove CIL workarounds for missing anon_inode class test_userfaultfd.te: adapt to upcoming Fedora policy changes

 policy/Makefile                  | 15 +++----
 policy/test_anon_inode_class.cil |  4 --
 policy/test_userfaultfd.cil      | 47 --------------------
 policy/test_userfaultfd.te       | 74 +++++++++++++++++++++++++-------
 4 files changed, 65 insertions(+), 75 deletions(-)
 delete mode 100644 policy/test_anon_inode_class.cil
 delete mode 100644 policy/test_userfaultfd.cil
Signature · 1 line
2.37.2
#1 lore raw

PATCH 1/2 policy: remove CIL workarounds for missing anon_inode class

The class has been declared in Fedora policy and refpolicy for quite some time, so simplify away the workarounds.

---
 policy/Makefile                  | 15 ++++---
 policy/test_anon_inode_class.cil |  4 --
 policy/test_userfaultfd.cil      | 47 ---------------------
 policy/test_userfaultfd.te       | 72 +++++++++++++++++++++++++-------
 4 files changed, 63 insertions(+), 75 deletions(-)
 delete mode 100644 policy/test_anon_inode_class.cil
 delete mode 100644 policy/test_userfaultfd.cil
policy/Makefile +7 -8
index 66734c6..b6f2f32 100644
@@ -37,14 +37,6 @@ endif
 
 ifeq ($(SUPPORTS_CIL),y)
 CIL_TARGETS = test_mlsconstrain.cil test_overlay_defaultrange.cil
-# userfaultfd test policy uses also xperms
-ifeq ($(shell [ $(MOD_POL_VERS) -ge 18 -a $(MAX_KERNEL_POLICY) -ge 30 ] && echo true),true)
-ifneq ($(shell grep -q anon_inode $(POLDEV)/include/support/all_perms.spt && echo true),true)
-CIL_TARGETS += test_anon_inode_class.cil
-endif
-CIL_TARGETS += test_userfaultfd.cil
-TARGETS += test_userfaultfd.te
-endif
 ifeq ($(shell [ $(MAX_KERNEL_POLICY) -ge 32 ] && echo true),true)
 ifeq ($(shell [ $(POL_VERS) -ge 32 ] && echo true),true)
 # If other MLS tests get written this can be moved outside of the glblub test
@@ -159,6 +151,13 @@ endif
 endif
 endif
 
+# userfaultfd test policy uses also xperms
+ifeq ($(shell [ $(MOD_POL_VERS) -ge 18 -a $(MAX_KERNEL_POLICY) -ge 30 ] && echo true),true)
+ifeq ($(shell grep -q anon_inode $(POLDEV)/include/support/all_perms.spt && echo true),true)
+TARGETS += test_userfaultfd.te
+endif
+endif
+
 ifeq (x$(DISTRO),$(filter x$(DISTRO),xRHEL4 xRHEL5 xRHEL6))
 TARGETS:=$(filter-out test_overlayfs.te test_mqueue.te test_ibpkey.te, $(TARGETS))
 endif
policy/test_anon_inode_class.cil deleted +0 -4
deleted file mode 100644
index 3e36599..0000000
@@ -1,4 +0,0 @@
-; Define new class anon_inode
-(class anon_inode ())
-(classcommon anon_inode file)
-(classorder (unordered anon_inode))
policy/test_userfaultfd.cil deleted +0 -47

47 lines not on this page · raw message

policy/test_userfaultfd.te +56 -16

97 lines not on this page · raw message

Signature · 1 line
2.37.2
#2 lore raw

PATCH 2/2 test_userfaultfd.te: adapt to upcoming Fedora policy changes

In reply to Ondrej Mosnacek

We plan to add automatic transitions for anon_inodes to the whole domain attribute, which would conflict with the testsuite's userfaultfd test. To avoid th conflict, use testsuite_domain_type_minimal() for the userfaultfd test domains, which doesn't add the types to the domain attribute.

---
 policy/test_userfaultfd.te | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
policy/test_userfaultfd.te +11 -9
index fe7f9c6..3046349 100644
@@ -10,14 +10,14 @@ type uffd_t;
 # Domain for confirming that without transition rule the userfaultfd
 # gets process' context
 type test_notransition_uffd_t;
-testsuite_domain_type(test_notransition_uffd_t)
+testsuite_domain_type_minimal(test_notransition_uffd_t)
 typeattribute test_notransition_uffd_t test_uffd_domain;
 
 allow test_notransition_uffd_t self:anon_inode { create getattr ioctl read };
 
 # Domain for process that has all the permissions to use userfaultfd
 type test_uffd_t;
-testsuite_domain_type(test_uffd_t)
+testsuite_domain_type_minimal(test_uffd_t)
 typeattribute test_uffd_t test_uffd_domain;
 
 type_transition test_uffd_t test_uffd_t:anon_inode uffd_t "[userfaultfd]";
@@ -25,14 +25,14 @@ allow test_uffd_t uffd_t:anon_inode { create getattr ioctl read };
 
 # Domain for process that cannot create userfaultfd
 type test_nocreate_uffd_t;
-testsuite_domain_type(test_nocreate_uffd_t)
+testsuite_domain_type_minimal(test_nocreate_uffd_t)
 typeattribute test_nocreate_uffd_t test_uffd_domain;
 
 type_transition test_nocreate_uffd_t test_nocreate_uffd_t:anon_inode uffd_t "[userfaultfd]";
 
 # Domain for process that cannot get attributed of userfaultfd
 type test_nogetattr_uffd_t;
-testsuite_domain_type(test_nogetattr_uffd_t)
+testsuite_domain_type_minimal(test_nogetattr_uffd_t)
 typeattribute test_nogetattr_uffd_t test_uffd_domain;
 
 type_transition test_nogetattr_uffd_t test_nogetattr_uffd_t:anon_inode uffd_t "[userfaultfd]";
@@ -40,7 +40,7 @@ allow test_nogetattr_uffd_t uffd_t:anon_inode { create };
 
 # Domain for process which can only use UFFDIO_API ioctl on userfaultfd
 type test_api_ioctl_uffd_t;
-testsuite_domain_type(test_api_ioctl_uffd_t)
+testsuite_domain_type_minimal(test_api_ioctl_uffd_t)
 typeattribute test_api_ioctl_uffd_t test_uffd_domain;
 
 type_transition test_api_ioctl_uffd_t test_api_ioctl_uffd_t:anon_inode uffd_t "[userfaultfd]";
@@ -50,7 +50,7 @@ allowxperm test_api_ioctl_uffd_t uffd_t:anon_inode ioctl { 0xaa3f };
 # Domain for process which can use UFFDIO_API and UFFDIO_REGISTER ioctls
 # on userfaultfd
 type test_register_ioctl_uffd_t;
-testsuite_domain_type(test_register_ioctl_uffd_t)
+testsuite_domain_type_minimal(test_register_ioctl_uffd_t)
 typeattribute test_register_ioctl_uffd_t test_uffd_domain;
 
 type_transition test_register_ioctl_uffd_t test_register_ioctl_uffd_t:anon_inode uffd_t "[userfaultfd]";
@@ -60,7 +60,7 @@ allowxperm test_register_ioctl_uffd_t uffd_t:anon_inode ioctl { 0xaa3f 0xaa00 };
 # Domain for process which can use UFFDIO_API, UFFDIO_REGISTER and
 # UFFDIO_COPY ioctls on userfaultfd
 type test_copy_ioctl_uffd_t;
-testsuite_domain_type(test_copy_ioctl_uffd_t)
+testsuite_domain_type_minimal(test_copy_ioctl_uffd_t)
 typeattribute test_copy_ioctl_uffd_t test_uffd_domain;
 
 type_transition test_copy_ioctl_uffd_t test_copy_ioctl_uffd_t:anon_inode uffd_t "[userfaultfd]";
@@ -69,7 +69,7 @@ allowxperm test_copy_ioctl_uffd_t uffd_t:anon_inode ioctl { 0xaa3f 0xaa00 0xaa03
 
 # Domain for process that cannot perform any ioctl operations on userfaultfd
 type test_noioctl_uffd_t;
-testsuite_domain_type(test_noioctl_uffd_t)
+testsuite_domain_type_minimal(test_noioctl_uffd_t)
 typeattribute test_noioctl_uffd_t test_uffd_domain;
 
 type_transition test_noioctl_uffd_t test_noioctl_uffd_t:anon_inode uffd_t "[userfaultfd]";
@@ -77,11 +77,13 @@ allow test_noioctl_uffd_t uffd_t:anon_inode { create getattr };
 
 # Domain for process that cannot read from userfaultfd
 type test_noread_uffd_t;
-testsuite_domain_type(test_noread_uffd_t)
+testsuite_domain_type_minimal(test_noread_uffd_t)
 typeattribute test_noread_uffd_t test_uffd_domain;
 
 type_transition test_noread_uffd_t test_noread_uffd_t:anon_inode uffd_t "[userfaultfd]";
 allow test_noread_uffd_t uffd_t:anon_inode { create getattr ioctl };
 
+# testsuite_domain_type_minimal() doesn't allow fork by default
+allow test_uffd_domain self:process { fork };
 # userfaultfd(2) requires CAP_SYS_PTRACE
 allow test_uffd_domain self:capability { sys_ptrace };
Signature · 1 line
2.37.2
Reviewed-by on v1 2/2
#3 lore raw

Re: [PATCH testsuite 2/2] test_userfaultfd.te: adapt to upcoming Fedora policy changes

Quoted 5 lines · Ondrej Mosnacek

We plan to add automatic transitions for anon_inodes to the whole domain attribute, which would conflict with the testsuite's userfaultfd test. To avoid th conflict, use testsuite_domain_type_minimal() for the userfaultfd test domains, which doesn't add the types to the domain attribute.

If you spin a second version, there's a minor typo in the commit message ("th conflict").

Regardless, for both patches:

#4 lore raw

Re: [PATCH testsuite 2/2] test_userfaultfd.te: adapt to upcoming Fedora policy changes

Quoted 9 lines · Daniel Burgener
Quoted 5 lines · Ondrej Mosnacek

We plan to add automatic transitions for anon_inodes to the whole domain attribute, which would conflict with the testsuite's userfaultfd test. To avoid th conflict, use testsuite_domain_type_minimal() for the userfaultfd test domains, which doesn't add the types to the domain attribute.

If you spin a second version, there's a minor typo in the commit message ("th conflict").

Yeah, I'll just fix that up locally before pushing to the upstream repo.

Quoted 4 lines

Regardless, for both patches:

Thanks :)

Signature · 3 lines
Ondrej Mosnacek
Senior Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.
#5 lore raw
In reply to Ondrej Mosnacek
Quoted 16 lines · Ondrej Mosnacek

See the description of the second patch for explanation. While there, the first patch cleans up the userfaultfd policy to be in just one file, since the CIL workaround is no longer needed.

Ondrej Mosnacek (2):
policy: remove CIL workarounds for missing anon_inode class test_userfaultfd.te: adapt to upcoming Fedora policy changes

 policy/Makefile                  | 15 +++----
 policy/test_anon_inode_class.cil |  4 --
 policy/test_userfaultfd.cil      | 47 --------------------
 policy/test_userfaultfd.te       | 74 +++++++++++++++++++++++++-------
 4 files changed, 65 insertions(+), 75 deletions(-)
 delete mode 100644 policy/test_anon_inode_class.cil
 delete mode 100644 policy/test_userfaultfd.cil
Quoted 2 lines

--
2.37.2

These patches are now applied.

Signature · 3 lines
Ondrej Mosnacek
Senior Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.