Skip to contentSkip to conversation

policy/test_secretmem.te: add anon_inode perms required in Linux v6.16-rc5

PATCH In review Paul Moore 2 participants 6 messages Jul 8, 2025 – Jul 10, 2025 SELinux security module

lore
Share & tools
lore

Paul Moore

author maintainer
#0 lore raw

PATCH 1/1 policy/test_secretmem.te: add anon_inode perms required in Linux v6.16-rc5

Starting with Linux v6.16-rc5 and commit cbe4134ea4bc
("fs: export anon_inode_make_secure_inode() and fix secretmem LSM bypass") secretmem's anonymous inodes are no longer marked as S_PRIVATE which means they are subject to a number of SELinux permission checks that has been previously skipped. This patch updates the test policy to account for these new checks and allows for a clean test run on Linux kernel builds with the above mentioned patch.

It is worth noting that there are still some capability/ipc_lock AVC denials when running the secretmem tests, but granting access to CAP_IPC_LOCK proved not to be strictly necessary for a clean test run so those rules were omitted from this patch.

---
 policy/test_secretmem.te | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
policy/test_secretmem.te +3 -3
index 357f41dd7574..32cc78d01f67 100644
@@ -13,12 +13,12 @@ testsuite_domain_type_minimal(test_nocreate_secretmem_t)
 # Domain allowed to create secret memory with the own domain type
 type test_create_secretmem_t;
 testsuite_domain_type_minimal(test_create_secretmem_t)
-allow test_create_secretmem_t self:anon_inode create;
+allow test_create_secretmem_t self:anon_inode { create map read write };
 
 # Domain allowed to create secret memory with the own domain type and allowed to map WX
 type test_create_wx_secretmem_t;
 testsuite_domain_type_minimal(test_create_wx_secretmem_t)
-allow test_create_wx_secretmem_t self:anon_inode create;
+allow test_create_wx_secretmem_t self:anon_inode { create map read write execute };
 allow test_create_wx_secretmem_t self:process execmem;
 
 # Domain not allowed to create secret memory via a type transition to a private type
@@ -30,4 +30,4 @@ type_transition test_nocreate_transition_secretmem_t test_nocreate_transition_se
 type test_create_transition_secretmem_t;
 testsuite_domain_type_minimal(test_create_transition_secretmem_t)
 type_transition test_create_transition_secretmem_t test_create_transition_secretmem_t:anon_inode test_secretmem_inode_t "[secretmem]";
-allow test_create_transition_secretmem_t test_secretmem_inode_t:anon_inode create;
+allow test_create_transition_secretmem_t test_secretmem_inode_t:anon_inode { create map read write };
Signature · 1 line
2.50.0
#1 lore raw
Quoted 9 lines · Paul Moore

Starting with Linux v6.16-rc5 and commit cbe4134ea4bc
("fs: export anon_inode_make_secure_inode() and fix secretmem LSM bypass") secretmem's anonymous inodes are no longer marked as S_PRIVATE which means they are subject to a number of SELinux permission checks that has been previously skipped. This patch updates the test policy to account for these new checks and allows for a clean test run on Linux kernel builds with the above mentioned patch.

Quoted 4 lines

It is worth noting that there are still some capability/ipc_lock AVC denials when running the secretmem tests, but granting access to CAP_IPC_LOCK proved not to be strictly necessary for a clean test run so those rules were omitted from this patch.

That comes from mlock_future_ok(), called from secretmem_mmap_prepare(). The control flow in that function should be restructured so that capable() is only called when the other conditions fail so that there are no spurious denials.

Quoted 12 lines
---
 policy/test_secretmem.te | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
policy/test_secretmem.te +0 -0
index 357f41dd7574..32cc78d01f67 100644
@@ -13,12 +13,12 @@ testsuite_domain_type_minimal(test_nocreate_secretmem_t)
 # Domain allowed to create secret memory with the own domain type

policy/test_secretmem.te testsuite_domain_type_minimal(test_nocreate_secretmem_t) · line 21

Quoted 10 lines
policy/test_secretmem.te +2 -2
 type test_create_secretmem_t;
 testsuite_domain_type_minimal(test_create_secretmem_t)
-allow test_create_secretmem_t self:anon_inode create;
+allow test_create_secretmem_t self:anon_inode { create map read write };
 
 # Domain allowed to create secret memory with the own domain type and allowed to map WX
 type test_create_wx_secretmem_t;
 testsuite_domain_type_minimal(test_create_wx_secretmem_t)
-allow test_create_wx_secretmem_t self:anon_inode create;
+allow test_create_wx_secretmem_t self:anon_inode { create map read write execute };

The { execute } permission isn't needed here. The test always calls memfd_secret() in the same way and it requires just read+write. test_create_wx_secretmem_t then mmaps the fd with PROT_EXEC in addition to PROT_READ | PROT_WRITE, but that doesn't require { execute } on the file, just process { execmem }.

I'm going to merge the patch with the extra permission dropped, since it's a minor change. I'm also going to add a Suggested-by for good measure, as Shivank originally drafted the patch. Thank you for taking time to formalize and test it!

Quoted 10 lines
policy/test_secretmem.te +1 -2
 allow test_create_wx_secretmem_t self:process execmem;
 
 # Domain not allowed to create secret memory via a type transition to a private type
@@ -30,4 +30,4 @@ type_transition test_nocreate_transition_secretmem_t test_nocreate_transition_se
 type test_create_transition_secretmem_t;
 testsuite_domain_type_minimal(test_create_transition_secretmem_t)
 type_transition test_create_transition_secretmem_t test_create_transition_secretmem_t:anon_inode test_secretmem_inode_t "[secretmem]";
-allow test_create_transition_secretmem_t test_secretmem_inode_t:anon_inode create;
+allow test_create_transition_secretmem_t test_secretmem_inode_t:anon_inode { create map read write };
--
Quoted 3 lines

2.50.0

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

#2 lore raw
Quoted 50 lines · Ondrej Mosnacek
Quoted 9 lines · Paul Moore

Starting with Linux v6.16-rc5 and commit cbe4134ea4bc
("fs: export anon_inode_make_secure_inode() and fix secretmem LSM bypass") secretmem's anonymous inodes are no longer marked as S_PRIVATE which means they are subject to a number of SELinux permission checks that has been previously skipped. This patch updates the test policy to account for these new checks and allows for a clean test run on Linux kernel builds with the above mentioned patch.

Quoted 4 lines

It is worth noting that there are still some capability/ipc_lock AVC denials when running the secretmem tests, but granting access to CAP_IPC_LOCK proved not to be strictly necessary for a clean test run so those rules were omitted from this patch.

That comes from mlock_future_ok(), called from secretmem_mmap_prepare(). The control flow in that function should be restructured so that capable() is only called when the other conditions fail so that there are no spurious denials.

Quoted 12 lines
---
 policy/test_secretmem.te | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
policy/test_secretmem.te +0 -0
index 357f41dd7574..32cc78d01f67 100644
@@ -13,12 +13,12 @@ testsuite_domain_type_minimal(test_nocreate_secretmem_t)
 # Domain allowed to create secret memory with the own domain type

policy/test_secretmem.te testsuite_domain_type_minimal(test_nocreate_secretmem_t) · line 21

Quoted 10 lines
policy/test_secretmem.te +2 -2
 type test_create_secretmem_t;
 testsuite_domain_type_minimal(test_create_secretmem_t)
-allow test_create_secretmem_t self:anon_inode create;
+allow test_create_secretmem_t self:anon_inode { create map read write };
 
 # Domain allowed to create secret memory with the own domain type and allowed to map WX
 type test_create_wx_secretmem_t;
 testsuite_domain_type_minimal(test_create_wx_secretmem_t)
-allow test_create_wx_secretmem_t self:anon_inode create;
+allow test_create_wx_secretmem_t self:anon_inode { create map read write execute };

The { execute } permission isn't needed here. The test always calls memfd_secret() in the same way and it requires just read+write. test_create_wx_secretmem_t then mmaps the fd with PROT_EXEC in addition to PROT_READ | PROT_WRITE, but that doesn't require { execute } on the file, just process { execmem }.

Quoted 4 lines

I'm going to merge the patch with the extra permission dropped, since it's a minor change. I'm also going to add a Suggested-by for good measure, as Shivank originally drafted the patch. Thank you for taking time to formalize and test it!

Applied: https://github.com/SELinuxProject/selinux-testsuite/commit/72e60b6018321a3da9d5e328477e29ee7366e498

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

I'm going to merge the patch with the extra permission dropped, since it's a minor change. I'm also going to add a Suggested-by for good measure, as Shivank originally drafted the patch. Thank you for taking time to formalize and test it!

A more careful reading of the other thread would have shown that Shivank and I arrived at the same/similar patch independently; the
Suggested-by: tag in this case is wrong. If it was the case that Shivank drafted the patch, you should have contacted him about adding a Signed-off-by: tag since he would have been the original author.

Signature · 1 line
paul-moore.com
#4 lore raw
Quoted 8 lines · Paul Moore
Quoted 5 lines · Ondrej Mosnacek

I'm going to merge the patch with the extra permission dropped, since it's a minor change. I'm also going to add a Suggested-by for good measure, as Shivank originally drafted the patch. Thank you for taking time to formalize and test it!

Quoted 5 lines

A more careful reading of the other thread would have shown that Shivank and I arrived at the same/similar patch independently; the
Suggested-by: tag in this case is wrong. If it was the case that Shivank drafted the patch, you should have contacted him about adding a Signed-off-by: tag since he would have been the original author.

Apologies, I must have read past that part :/ You're right, I messed it up... I guess it's not worth a force push to the main branch, but let me know if you'd prefer that.

Signature · 3 lines
Ondrej Mosnacek
Senior Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.
author maintainer
#5 lore raw
Quoted 14 lines · Ondrej Mosnacek
Quoted 7 lines · Paul Moore
Quoted 5 lines · Ondrej Mosnacek

I'm going to merge the patch with the extra permission dropped, since it's a minor change. I'm also going to add a Suggested-by for good measure, as Shivank originally drafted the patch. Thank you for taking time to formalize and test it!

Quoted 5 lines

A more careful reading of the other thread would have shown that Shivank and I arrived at the same/similar patch independently; the
Suggested-by: tag in this case is wrong. If it was the case that Shivank drafted the patch, you should have contacted him about adding a Signed-off-by: tag since he would have been the original author.

Quoted 3 lines

Apologies, I must have read past that part :/ You're right, I messed it up... I guess it's not worth a force push to the main branch, but let me know if you'd prefer that.

The important part is the DCO sign-off, and that's correct, so I'd say just leave it as-is and take this as a lesson for next time.

Signature · 1 line
paul-moore.com