Skip to contentSkip to conversation

testsuite: fix cap_userns for kernels >= v5.12

PATCH In review Paul Moore 2 participants 3 messages Apr 26, 2021 – Apr 27, 2021 SELinux security module

lore
Share & tools
lore

Paul Moore

author maintainer
#0 lore raw

PATCH 1/1 testsuite: fix cap_userns for kernels >= v5.12

Starting with Linux v5.12 CAP_SETFCAP is required to map UID 0/root. This is due to kernel commit db2e718a4798 ("capabilities: require CAP_SETFCAP to map uid 0"). In order to resolve this in the test suite allow the test_cap_userns_t domain to exercise the setfcap capability.

---
 policy/test_cap_userns.te |    1 +
 1 file changed, 1 insertion(+)
policy/test_cap_userns.te +1 -0
index ab74325..052afea 100644
@@ -14,6 +14,7 @@ typeattribute test_cap_userns_t capusernsdomain;
 
 # This domain is allowed sys_admin on non-init userns for mount.
 allow test_cap_userns_t self:cap_userns sys_admin;
+allow test_cap_userns_t self:capability setfcap;
 
 # Domain for process that is not allowed non-init userns capabilities
 type test_no_cap_userns_t;
#1 lore raw
Quoted 5 lines · Paul Moore

Starting with Linux v5.12 CAP_SETFCAP is required to map UID 0/root. This is due to kernel commit db2e718a4798 ("capabilities: require CAP_SETFCAP to map uid 0"). In order to resolve this in the test suite allow the test_cap_userns_t domain to exercise the setfcap capability.

Thanks! We hit this in our mainline kernel CI as well and I was going to send a patch for this, but I didn't have the right kernel build at hand to test, so I deferred it. One comment below.

Quoted 11 lines
---
 policy/test_cap_userns.te |    1 +
 1 file changed, 1 insertion(+)
policy/test_cap_userns.te +0 -0
index ab74325..052afea 100644

policy/test_cap_userns.te typeattribute test_cap_userns_t capusernsdomain; · line 17

Quoted 4 lines
policy/test_cap_userns.te +1 -0
@@ -14,6 +14,7 @@ typeattribute test_cap_userns_t capusernsdomain;
 
 # This domain is allowed sys_admin on non-init userns for mount.
 allow test_cap_userns_t self:cap_userns sys_admin;
+allow test_cap_userns_t self:capability setfcap;

I think we should allow the capability to both domains (i.e. to capusernsdomain). We are testing cap_userns::sys_admin here and if the tested operation is not denied for a domain that has only capability::setfcap, we want the test to fail.

Also, a comment with a sentence explaining why CAP_SETFCAP is needed would be nice :)

policy/test_cap_userns.te typeattribute test_cap_userns_t capusernsdomain;

Quoted 4 lines
policy/test_cap_userns.te +0 -0
 # Domain for process that is not allowed non-init userns capabilities
 type test_no_cap_userns_t;
 

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

author maintainer
#2 lore raw
Quoted 16 lines · Ondrej Mosnacek

policy/test_cap_userns.te typeattribute test_cap_userns_t capusernsdomain; · line 17

Quoted 9 lines · Paul Moore
policy/test_cap_userns.te +1 -0
index ab74325..052afea 100644
@@ -14,6 +14,7 @@ typeattribute test_cap_userns_t capusernsdomain;
 
 # This domain is allowed sys_admin on non-init userns for mount.
 allow test_cap_userns_t self:cap_userns sys_admin;
+allow test_cap_userns_t self:capability setfcap;

I think we should allow the capability to both domains (i.e. to capusernsdomain). We are testing cap_userns::sys_admin here and if the tested operation is not denied for a domain that has only capability::setfcap, we want the test to fail.

Quoted 2 lines

Also, a comment with a sentence explaining why CAP_SETFCAP is needed would be nice :)

Fair enough, v2 will be out shortly.

Signature · 2 lines
paul moore
www.paul-moore.com