Skip to contentSkip to conversation

policy: allow user_namespace::create where appropriate

PATCH In review Ondrej Mosnacek 2 participants 3 messages Dec 9, 2022 – Dec 12, 2022 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 policy: allow user_namespace::create where appropriate

The cap_userns test's helper program needs this new permission for its operation - detect the support of it and conditionally add the necessary rule.

---
 policy/Makefile           | 4 ++++
 policy/test_cap_userns.te | 1 +
 policy/test_global.te     | 4 ++++
 3 files changed, 9 insertions(+)
policy/Makefile +4 -0
index 403802b..f18e15d 100644
@@ -166,6 +166,10 @@ ifeq ($(shell grep -q anon_inode $(POLDEV)/include/support/all_perms.spt && echo
 TARGETS += test_secretmem.te
 endif
 
+ifeq ($(shell grep -q user_namespace $(POLDEV)/include/support/all_perms.spt && echo true),true)
+export M4PARAM += -Duser_namespace_defined
+endif
+
 all: build
 
 expand_check:
policy/test_cap_userns.te +1 -0
index 3e68feb..6f44487 100644
@@ -19,5 +19,6 @@ testsuite_domain_type(test_no_cap_userns_t)
 typeattribute test_no_cap_userns_t capusernsdomain;
 
 # Rules common to both domains.
+allow_userns_create(capusernsdomain)
 # linux >= v5.12 needs setfcap to map UID 0
 allow capusernsdomain self:capability setfcap;
policy/test_global.te +4 -0
index 1b20cbc..e95102a 100644
@@ -171,3 +171,7 @@ ifdef(`lockdown_defined', `allow $1 self:lockdown integrity;')
 define(`allow_lockdown_confidentiality',
 ifdef(`lockdown_defined', `allow $1 self:lockdown confidentiality;')
 )
+
+define(`allow_userns_create',
+ifdef(`user_namespace_defined', `allow $1 self:user_namespace create;')
+)
Signature · 1 line
2.38.1
#1 lore raw
Quoted 51 lines · Ondrej Mosnacek

The cap_userns test's helper program needs this new permission for its operation - detect the support of it and conditionally add the necessary rule.

---
 policy/Makefile           | 4 ++++
 policy/test_cap_userns.te | 1 +
 policy/test_global.te     | 4 ++++
 3 files changed, 9 insertions(+)
policy/Makefile +4 -0
index 403802b..f18e15d 100644
@@ -166,6 +166,10 @@ ifeq ($(shell grep -q anon_inode $(POLDEV)/include/support/all_perms.spt && echo
 TARGETS += test_secretmem.te
 endif
 
+ifeq ($(shell grep -q user_namespace $(POLDEV)/include/support/all_perms.spt && echo true),true)
+export M4PARAM += -Duser_namespace_defined
+endif
+
 all: build
 
 expand_check:
policy/test_cap_userns.te +1 -0
index 3e68feb..6f44487 100644
@@ -19,5 +19,6 @@ testsuite_domain_type(test_no_cap_userns_t)
 typeattribute test_no_cap_userns_t capusernsdomain;
 
 # Rules common to both domains.
+allow_userns_create(capusernsdomain)
 # linux >= v5.12 needs setfcap to map UID 0
 allow capusernsdomain self:capability setfcap;
policy/test_global.te +4 -1
index 1b20cbc..e95102a 100644
@@ -171,3 +171,7 @@ ifdef(`lockdown_defined', `allow $1 self:lockdown integrity;')
 define(`allow_lockdown_confidentiality',
 ifdef(`lockdown_defined', `allow $1 self:lockdown confidentiality;')
 )
+
+define(`allow_userns_create',
+ifdef(`user_namespace_defined', `allow $1 self:user_namespace create;')
+)
--
Quoted 2 lines

2.38.1

This patch is now applied:
https://github.com/SELinuxProject/selinux-testsuite/commit/3389abeaa3bb6fdf23a0f2d8b1550fae69f9c52e

Signature · 3 lines
Ondrej Mosnacek
Senior Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.
maintainer
#2 lore raw
Quoted 13 lines · Ondrej Mosnacek
Quoted 11 lines · Ondrej Mosnacek

The cap_userns test's helper program needs this new permission for its operation - detect the support of it and conditionally add the necessary rule.

---
 policy/Makefile           | 4 ++++
 policy/test_cap_userns.te | 1 +
 policy/test_global.te     | 4 ++++
 3 files changed, 9 insertions(+)

...

Quoted 2 lines

This patch is now applied:
https://github.com/SELinuxProject/selinux-testsuite/commit/3389abeaa3bb6fdf23a0f2d8b1550fae69f9c52e

Thanks

Signature · 1 line
paul-moore.com