Skip to contentSkip to conversation

test_userfaultfd.te: grant test_uffd_domain CAP_SYS_PTRACE

PATCH In review Ondrej Mosnacek 2 participants 3 messages Jan 25, 2021 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test_userfaultfd.te: grant test_uffd_domain CAP_SYS_PTRACE

userfaultfd(2) requires the caller to have CAP_SYS_PTRACE if the vm.unprivileged_userfaultfd sysctl is set to 0, so grant all userfaultfd test domains the corresponding SELinux permission, otherwise the tests will fail when the sysctl is set to 0 (e.g. Fedora 34+).

While there, also remove a commented-out rule that doesn't need to be there.

Fixes 2ea007924363 ("selinux-testsuite: Add userfaultfd test")
---
 policy/test_userfaultfd.te | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
policy/test_userfaultfd.te +3 -1
index e29723d..f15ef89 100644
@@ -44,8 +44,10 @@ userfaultfd_domain_type(test_noioctl_uffd_t)
 # Domain for process that cannot read from userfaultfd
 userfaultfd_domain_type(test_noread_uffd_t)
 
+# userfaultfd(2) requires CAP_SYS_PTRACE
+allow test_uffd_domain self:capability { sys_ptrace };
+
 # Allow all of these domains to be executed
-#allow test_uffd_domain test_file_t:file { entrypoint map execute };
 miscfiles_domain_entry_test_files(test_uffd_domain)
 unconfined_runs_test(test_uffd_domain)
 userdom_sysadm_entry_spec_domtrans_to(test_uffd_domain)
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Ondrej Mosnacek

userfaultfd(2) requires the caller to have CAP_SYS_PTRACE if the vm.unprivileged_userfaultfd sysctl is set to 0, so grant all userfaultfd test domains the corresponding SELinux permission, otherwise the tests will fail when the sysctl is set to 0 (e.g. Fedora 34+).

While there, also remove a commented-out rule that doesn't need to be there.

Fixes 2ea007924363 ("selinux-testsuite: Add userfaultfd test")

Sorry for overlooking this earlier.

Quoted 23 lines
---
 policy/test_userfaultfd.te | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
policy/test_userfaultfd.te +3 -2
index e29723d..f15ef89 100644
@@ -44,8 +44,10 @@ userfaultfd_domain_type(test_noioctl_uffd_t)
 # Domain for process that cannot read from userfaultfd
 userfaultfd_domain_type(test_noread_uffd_t)
 
+# userfaultfd(2) requires CAP_SYS_PTRACE
+allow test_uffd_domain self:capability { sys_ptrace };
+
 # Allow all of these domains to be executed
-#allow test_uffd_domain test_file_t:file { entrypoint map execute };
 miscfiles_domain_entry_test_files(test_uffd_domain)
 unconfined_runs_test(test_uffd_domain)
 userdom_sysadm_entry_spec_domtrans_to(test_uffd_domain)
--

2.29.2

#2 lore raw
Quoted 7 lines · Lokesh Gidra
Quoted 6 lines · Ondrej Mosnacek

userfaultfd(2) requires the caller to have CAP_SYS_PTRACE if the vm.unprivileged_userfaultfd sysctl is set to 0, so grant all userfaultfd test domains the corresponding SELinux permission, otherwise the tests will fail when the sysctl is set to 0 (e.g. Fedora 34+).

Quoted 8 lines
Quoted 5 lines

While there, also remove a commented-out rule that doesn't need to be there.

Fixes 2ea007924363 ("selinux-testsuite: Add userfaultfd test")

Sorry for overlooking this earlier.

No worries, the behavior depends on sysctl configuration, so it was easy to miss :) And part of the blame is on me for not re-testing the patch on rawhide against a kernel with the related patches applied...

I'm going to merge the patch in a while, since it fixes a bug and is fairly trivial.

Quoted 12 lines
Quoted 12 lines
---
 policy/test_userfaultfd.te | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
policy/test_userfaultfd.te +0 -0
index e29723d..f15ef89 100644
@@ -44,8 +44,10 @@ userfaultfd_domain_type(test_noioctl_uffd_t)
 # Domain for process that cannot read from userfaultfd
 userfaultfd_domain_type(test_noread_uffd_t)
 
Quoted 12 lines
Quoted 11 lines
policy/test_userfaultfd.te +3 -2
+# userfaultfd(2) requires CAP_SYS_PTRACE
+allow test_uffd_domain self:capability { sys_ptrace };
+
 # Allow all of these domains to be executed
-#allow test_uffd_domain test_file_t:file { entrypoint map execute };
 miscfiles_domain_entry_test_files(test_uffd_domain)
 unconfined_runs_test(test_uffd_domain)
 userdom_sysadm_entry_spec_domtrans_to(test_uffd_domain)
--

2.29.2

--
Ondrej Mosnacek
Software Engineer, Platform Security - SELinux kernel Red Hat, Inc.