policy/test_secretmem.te: add anon_inode perms required in Linux v6.16-rc5
Paul Moore
maintainerPATCH 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
@@ -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
Quoted 9 lines · Paul Moore
Starting with Linux v6.16-rc5 and commit
cbe4134ea4bc
("fs: exportanon_inode_make_secure_inode()and fix secretmem LSM bypass") secretmem's anonymous inodes are no longer marked asS_PRIVATEwhich 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_LOCKproved 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
Signed-off-by Paul Moore <[email protected]>--- policy/test_secretmem.te | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)policy/test_secretmem.te +0
-0@@ -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
-2type 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
-2allow 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.
Quoted 50 lines · Ondrej Mosnacek
Quoted 9 lines · Paul Moore
Starting with Linux v6.16-rc5 and commit
cbe4134ea4bc
("fs: exportanon_inode_make_secure_inode()and fix secretmem LSM bypass") secretmem's anonymous inodes are no longer marked asS_PRIVATEwhich 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_LOCKproved 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 fromsecretmem_mmap_prepare(). The control flow in that function should be restructured so thatcapable()is only called when the other conditions fail so that there are no spurious denials.Quoted 12 lines
Signed-off-by Paul Moore <[email protected]>--- policy/test_secretmem.te | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)policy/test_secretmem.te +0
-0@@ -13,12 +13,12 @@ testsuite_domain_type_minimal(test_nocreate_secretmem_t) # Domain allowed to create secret memory with the own domain typepolicy/test_secretmem.te testsuite_domain_type_minimal(test_nocreate_secretmem_t) · line 21
Quoted 10 lines
policy/test_secretmem.te +2
-2type 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_tthen mmaps the fd withPROT_EXECin addition toPROT_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.
Paul Moore
maintainerQuoted 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
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.
Paul Moore
maintainerQuoted 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