Skip to contentSkip to conversation

policy: only define anon_inode class if not defined in system policy

PATCH In review Ondrej Mosnacek 2 participants 4 messages Apr 30, 2021 – May 1, 2021 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 policy: only define anon_inode class if not defined in system policy

When the system policy already defines this class, loading the test policy fails with:

Re-declaration of class anon_inode
Previous declaration of class at /var/lib/selinux/targeted/tmp/modules/100/base/cil:1003 Bad class declaration at /var/lib/selinux/targeted/tmp/modules/400/test_userfaultfd/cil:2 /usr/sbin/semodule: Failed!

Fix this by only including the anon_inode class declarations when it's not found in the system policy headers.

Fixes 2ea007924363 ("selinux-testsuite: Add userfaultfd test")
---
 policy/Makefile                  | 3 +++
 policy/test_anon_inode_class.cil | 4 ++++
 policy/test_userfaultfd.cil      | 5 -----
 3 files changed, 7 insertions(+), 5 deletions(-)
 create mode 100644 policy/test_anon_inode_class.cil
policy/Makefile +3 -0
index 91364d5..dee55a2 100644
@@ -39,6 +39,9 @@ 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
policy/test_anon_inode_class.cil new file +4 -0
new file mode 100644
index 0000000..3e36599
@@ -0,0 +1,4 @@
+; Define new class anon_inode
+(class anon_inode ())
+(classcommon anon_inode file)
+(classorder (unordered anon_inode))
policy/test_userfaultfd.cil +0 -5
index 18d5f3f..f6a6791 100644
@@ -1,8 +1,3 @@
-; Define new class anon_inode
-(class anon_inode ())
-(classcommon anon_inode file)
-(classorder (unordered anon_inode))
-
 ; Allow all anonymous inodes
 (typeattributeset cil_gen_require test_notransition_uffd_t)
 (allow test_notransition_uffd_t self (anon_inode (create getattr ioctl read)))
Signature · 1 line
2.30.2
#1 lore raw
Quoted 10 lines · Ondrej Mosnacek

When the system policy already defines this class, loading the test policy fails with:

Re-declaration of class anon_inode
Previous declaration of class at /var/lib/selinux/targeted/tmp/modules/100/base/cil:1003 Bad class declaration at /var/lib/selinux/targeted/tmp/modules/400/test_userfaultfd/cil:2 /usr/sbin/semodule: Failed!

Fix this by only including the anon_inode class declarations when it's not found in the system policy headers.

Reference policy does not have a "all_perms.spt" AFAIK. This might only work with Fedora.

Quoted 47 lines
Fixes 2ea007924363 ("selinux-testsuite: Add userfaultfd test")
---
 policy/Makefile                  | 3 +++
 policy/test_anon_inode_class.cil | 4 ++++
 policy/test_userfaultfd.cil      | 5 -----
 3 files changed, 7 insertions(+), 5 deletions(-)
 create mode 100644 policy/test_anon_inode_class.cil
policy/Makefile +3 -0
index 91364d5..dee55a2 100644
@@ -39,6 +39,9 @@ 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
policy/test_anon_inode_class.cil new file +4 -0
new file mode 100644
index 0000000..3e36599
@@ -0,0 +1,4 @@
+; Define new class anon_inode
+(class anon_inode ())
+(classcommon anon_inode file)
+(classorder (unordered anon_inode))
policy/test_userfaultfd.cil +0 -5
index 18d5f3f..f6a6791 100644
@@ -1,8 +1,3 @@
-; Define new class anon_inode
-(class anon_inode ())
-(classcommon anon_inode file)
-(classorder (unordered anon_inode))
-
 ; Allow all anonymous inodes
 (typeattributeset cil_gen_require test_notransition_uffd_t)
 (allow test_notransition_uffd_t self (anon_inode (create getattr ioctl read)))
Signature · 4 lines
gpg --locate-keys [email protected]
Key fingerprint = FCD2 3660 5D6B 9D27 7FC6  E0FF DA7E 521F 10F6 4098
https://sks-keyservers.net/pks/lookup?op=get&search=0xDA7E521F10F64098
Dominick Grift
#2 lore raw
Quoted 10 lines · Dominick Grift
Quoted 8 lines · Ondrej Mosnacek

When the system policy already defines this class, loading the test policy fails with:

Re-declaration of class anon_inode
Previous declaration of class at /var/lib/selinux/targeted/tmp/modules/100/base/cil:1003 Bad class declaration at /var/lib/selinux/targeted/tmp/modules/400/test_userfaultfd/cil:2 /usr/sbin/semodule: Failed!

Quoted 5 lines
Quoted 2 lines

Fix this by only including the anon_inode class declarations when it's not found in the system policy headers.

Reference policy does not have a "all_perms.spt" AFAIK. This might only work with Fedora.

Could be, but this pattern is already used elsewhere in the testsuite, so for now this'll have to do...

Quoted 55 lines
Quoted 40 lines
Fixes 2ea007924363 ("selinux-testsuite: Add userfaultfd test")
---
 policy/Makefile                  | 3 +++
 policy/test_anon_inode_class.cil | 4 ++++
 policy/test_userfaultfd.cil      | 5 -----
 3 files changed, 7 insertions(+), 5 deletions(-)
 create mode 100644 policy/test_anon_inode_class.cil
policy/Makefile +3 -0
index 91364d5..dee55a2 100644
@@ -39,6 +39,9 @@ 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
policy/test_anon_inode_class.cil new file +4 -0
new file mode 100644
index 0000000..3e36599
@@ -0,0 +1,4 @@
+; Define new class anon_inode
+(class anon_inode ())
+(classcommon anon_inode file)
+(classorder (unordered anon_inode))
policy/test_userfaultfd.cil +0 -0
index 18d5f3f..f6a6791 100644

policy/test_userfaultfd.cil line 3

Quoted 8 lines
policy/test_userfaultfd.cil +0 -5
@@ -1,8 +1,3 @@
-; Define new class anon_inode
-(class anon_inode ())
-(classcommon anon_inode file)
-(classorder (unordered anon_inode))
-
 ; Allow all anonymous inodes
 (typeattributeset cil_gen_require test_notransition_uffd_t)
 (allow test_notransition_uffd_t self (anon_inode (create getattr ioctl read)))

--
gpg --locate-keys [email protected]
Key fingerprint = FCD2 3660 5D6B 9D27 7FC6 E0FF DA7E 521F 10F6 4098
https://sks-keyservers.net/pks/lookup?op=get&search=0xDA7E521F10F64098
Dominick Grift

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

When the system policy already defines this class, loading the test policy fails with:

Re-declaration of class anon_inode
Previous declaration of class at /var/lib/selinux/targeted/tmp/modules/100/base/cil:1003 Bad class declaration at /var/lib/selinux/targeted/tmp/modules/400/test_userfaultfd/cil:2 /usr/sbin/semodule: Failed!

Fix this by only including the anon_inode class declarations when it's not found in the system policy headers.

Fixes 2ea007924363 ("selinux-testsuite: Add userfaultfd test")
---
 policy/Makefile                  | 3 +++
 policy/test_anon_inode_class.cil | 4 ++++
 policy/test_userfaultfd.cil      | 5 -----
 3 files changed, 7 insertions(+), 5 deletions(-)
 create mode 100644 policy/test_anon_inode_class.cil
policy/Makefile +3 -0
index 91364d5..dee55a2 100644
@@ -39,6 +39,9 @@ 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
policy/test_anon_inode_class.cil new file +4 -0
new file mode 100644
index 0000000..3e36599
@@ -0,0 +1,4 @@
+; Define new class anon_inode
+(class anon_inode ())
+(classcommon anon_inode file)
+(classorder (unordered anon_inode))
policy/test_userfaultfd.cil +0 -6
index 18d5f3f..f6a6791 100644
@@ -1,8 +1,3 @@
-; Define new class anon_inode
-(class anon_inode ())
-(classcommon anon_inode file)
-(classorder (unordered anon_inode))
-
 ; Allow all anonymous inodes
 (typeattributeset cil_gen_require test_notransition_uffd_t)
 (allow test_notransition_uffd_t self (anon_inode (create getattr ioctl read)))
--
Quoted 1 line

2.30.2

Now applied:
https://github.com/SELinuxProject/selinux-testsuite/commit/9267bc9fbc1b31107eac42b0870075507c5a2e6c

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