Skip to contentSkip to conversation

selinux: adjust the !file/memfd_file error handling on execute

PATCH In review Paul Moore 3 participants 19 messages Sep 9, 2025 – Sep 18, 2025 SELinux security module

lore
Share & tools
lore

Paul Moore

author maintainer
#0 lore raw

PATCH 1/1 selinux: adjust the !file/memfd_file error handling on execute

A prior commit, see the 'Fixes:' tag below, added support for a new object class, memfd_file. As part of that change, support for the new object class was added to selinux_bprm_creds_for_exec() to facilitate execution of memfd_file objects using fexecvc(2), or similar. This patch adjusts some of the sanity checking added in that commit to avoid a "silent denial" in the case of a kernel bug as well as return -EACCES instead of -EPERM so that we can more easily distinguish between a permission denial and a fault in the code.

Fixes 084f547bd8e3 ("memfd,selinux: call security_inode_init_security_anon()")
---
 security/selinux/hooks.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
security/selinux/hooks.c +3 -2
index b2ad83353c17..2b685f9dd61d 100644
@@ -2320,8 +2320,9 @@ static int selinux_bprm_creds_for_exec(struct linux_binprm *bprm)
 	new_tsec = selinux_cred(bprm->cred);
 	isec = inode_security(inode);
 
-	if (isec->sclass != SECCLASS_FILE && isec->sclass != SECCLASS_MEMFD_FILE)
-		return -EPERM;
+	if (WARN_ON(isec->sclass != SECCLASS_FILE &&
+		    isec->sclass != SECCLASS_MEMFD_FILE))
+		return -EACCES;
 
 	/* Default to the current task SID. */
 	new_tsec->sid = old_tsec->sid;
Signature · 1 line
2.51.0
author maintainer
#1 lore raw
Quoted 10 lines · Paul Moore

A prior commit, see the 'Fixes:' tag below, added support for a new object class, memfd_file. As part of that change, support for the new object class was added to selinux_bprm_creds_for_exec() to facilitate execution of memfd_file objects using fexecvc(2), or similar. This patch adjusts some of the sanity checking added in that commit to avoid a "silent denial" in the case of a kernel bug as well as return -EACCES instead of -EPERM so that we can more easily distinguish between a permission denial and a fault in the code.

Quoted 5 lines
Fixes 084f547bd8e3 ("memfd,selinux: call security_inode_init_security_anon()")
---
 security/selinux/hooks.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

FYI, as of right now this is untested, but a test kernel is building as I write this ...

Quoted 18 lines
security/selinux/hooks.c +3 -3
index b2ad83353c17..2b685f9dd61d 100644
@@ -2320,8 +2320,9 @@ static int selinux_bprm_creds_for_exec(struct linux_binprm *bprm)
        new_tsec = selinux_cred(bprm->cred);
        isec = inode_security(inode);
 
-       if (isec->sclass != SECCLASS_FILE && isec->sclass != SECCLASS_MEMFD_FILE)
-               return -EPERM;
+       if (WARN_ON(isec->sclass != SECCLASS_FILE &&
+                   isec->sclass != SECCLASS_MEMFD_FILE))
+               return -EACCES;
 
        /* Default to the current task SID. */
        new_tsec->sid = old_tsec->sid;
--

2.51.0

Signature · 1 line
paul-moore.com
author maintainer
#2 lore raw
Quoted 11 lines · Paul Moore
Quoted 10 lines · Paul Moore

A prior commit, see the 'Fixes:' tag below, added support for a new object class, memfd_file. As part of that change, support for the new object class was added to selinux_bprm_creds_for_exec() to facilitate execution of memfd_file objects using fexecvc(2), or similar. This patch adjusts some of the sanity checking added in that commit to avoid a "silent denial" in the case of a kernel bug as well as return -EACCES instead of -EPERM so that we can more easily distinguish between a permission denial and a fault in the code.

Quoted 8 lines
Quoted 5 lines
Fixes 084f547bd8e3 ("memfd,selinux: call security_inode_init_security_anon()")
---
 security/selinux/hooks.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

FYI, as of right now this is untested, but a test kernel is building as I write this ...

I was delayed slightly as it turns out the latest Rawhide dracut packages are broken, but kernel boots and passes the (unmodified) selinux-testsuite. If anyone who has an updated/patched toolchain, policy, test suite, etc. can verify everything is still okay when the new policy capability is enabled I would appreciate it.

Quoted 18 lines
Quoted 18 lines
security/selinux/hooks.c +3 -3
index b2ad83353c17..2b685f9dd61d 100644
@@ -2320,8 +2320,9 @@ static int selinux_bprm_creds_for_exec(struct linux_binprm *bprm)
        new_tsec = selinux_cred(bprm->cred);
        isec = inode_security(inode);
 
-       if (isec->sclass != SECCLASS_FILE && isec->sclass != SECCLASS_MEMFD_FILE)
-               return -EPERM;
+       if (WARN_ON(isec->sclass != SECCLASS_FILE &&
+                   isec->sclass != SECCLASS_MEMFD_FILE))
+               return -EACCES;
 
        /* Default to the current task SID. */
        new_tsec->sid = old_tsec->sid;
--

2.51.0

Signature · 1 line
paul-moore.com
#3 lore raw
Quoted 19 lines · Paul Moore
Quoted 17 lines · Paul Moore
Quoted 15 lines · Paul Moore

A prior commit, see the 'Fixes:' tag below, added support for a new object class, memfd_file. As part of that change, support for the new object class was added to selinux_bprm_creds_for_exec() to facilitate execution of memfd_file objects using fexecvc(2), or similar. This patch adjusts some of the sanity checking added in that commit to avoid a "silent denial" in the case of a kernel bug as well as return -EACCES instead of -EPERM so that we can more easily distinguish between a permission denial and a fault in the code.

Fixes 084f547bd8e3 ("memfd,selinux: call security_inode_init_security_anon()")
---
 security/selinux/hooks.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 8 lines
Quoted 2 lines

FYI, as of right now this is untested, but a test kernel is building as I write this ...

I was delayed slightly as it turns out the latest Rawhide dracut packages are broken, but kernel boots and passes the (unmodified) selinux-testsuite. If anyone who has an updated/patched toolchain, policy, test suite, etc. can verify everything is still okay when the new policy capability is enabled I would appreciate it.

I just did. LGTM.

author maintainer
#4 lore raw
Quoted 23 lines · Thiébaud Weksteen
Quoted 22 lines · Paul Moore
Quoted 19 lines · Paul Moore
Quoted 10 lines · Paul Moore

A prior commit, see the 'Fixes:' tag below, added support for a new object class, memfd_file. As part of that change, support for the new object class was added to selinux_bprm_creds_for_exec() to facilitate execution of memfd_file objects using fexecvc(2), or similar. This patch adjusts some of the sanity checking added in that commit to avoid a "silent denial" in the case of a kernel bug as well as return -EACCES instead of -EPERM so that we can more easily distinguish between a permission denial and a fault in the code.

Quoted 5 lines
Fixes 084f547bd8e3 ("memfd,selinux: call security_inode_init_security_anon()")
---
 security/selinux/hooks.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

FYI, as of right now this is untested, but a test kernel is building as I write this ...

Quoted 7 lines
Quoted 5 lines

I was delayed slightly as it turns out the latest Rawhide dracut packages are broken, but kernel boots and passes the (unmodified) selinux-testsuite. If anyone who has an updated/patched toolchain, policy, test suite, etc. can verify everything is still okay when the new policy capability is enabled I would appreciate it.

I just did. LGTM.

Thanks :)

Quoted 1 line
Signature · 1 line
paul-moore.com
maintainer Acked-by on v1 1/1
#5 lore raw
In reply to Paul Moore
Quoted 9 lines · Paul Moore

A prior commit, see the 'Fixes:' tag below, added support for a new object class, memfd_file. As part of that change, support for the new object class was added to selinux_bprm_creds_for_exec() to facilitate execution of memfd_file objects using fexecvc(2), or similar. This patch adjusts some of the sanity checking added in that commit to avoid a "silent denial" in the case of a kernel bug as well as return -EACCES instead of -EPERM so that we can more easily distinguish between a permission denial and a fault in the code.

Technically, this doesn't make it easier to distinguish because we usually return -EACCES from avc_has_perm() and friends, but return -EPERM for capability denials and in certain other cases (not always clear why, arguably a bug unless we were just replicating the error number for some existing check that also returned -EPERM). My suggestion to use -EACCES was because that is more consistent with how we report denials outside of capability checks.
To actually test this, would need an updated libsepol patch that deals with the fact that the policy capability number changed on merge, or re-basing the original patch on top. Otherwise,

Quoted 26 lines
Fixes 084f547bd8e3 ("memfd,selinux: call security_inode_init_security_anon()")
---
 security/selinux/hooks.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
security/selinux/hooks.c +3 -3
index b2ad83353c17..2b685f9dd61d 100644
@@ -2320,8 +2320,9 @@ static int selinux_bprm_creds_for_exec(struct linux_binprm *bprm)
        new_tsec = selinux_cred(bprm->cred);
        isec = inode_security(inode);
 
-       if (isec->sclass != SECCLASS_FILE && isec->sclass != SECCLASS_MEMFD_FILE)
-               return -EPERM;
+       if (WARN_ON(isec->sclass != SECCLASS_FILE &&
+                   isec->sclass != SECCLASS_MEMFD_FILE))
+               return -EACCES;
 
        /* Default to the current task SID. */
        new_tsec->sid = old_tsec->sid;
--

2.51.0

maintainer Tested-by
#6 lore raw
Quoted 22 lines · Stephen Smalley
Quoted 9 lines · Paul Moore

A prior commit, see the 'Fixes:' tag below, added support for a new object class, memfd_file. As part of that change, support for the new object class was added to selinux_bprm_creds_for_exec() to facilitate execution of memfd_file objects using fexecvc(2), or similar. This patch adjusts some of the sanity checking added in that commit to avoid a "silent denial" in the case of a kernel bug as well as return -EACCES instead of -EPERM so that we can more easily distinguish between a permission denial and a fault in the code.

Technically, this doesn't make it easier to distinguish because we usually return -EACCES from avc_has_perm() and friends, but return -EPERM for capability denials and in certain other cases (not always clear why, arguably a bug unless we were just replicating the error number for some existing check that also returned -EPERM). My suggestion to use -EACCES was because that is more consistent with how we report denials outside of capability checks.
To actually test this, would need an updated libsepol patch that deals with the fact that the policy capability number changed on merge, or re-basing the original patch on top. Otherwise,

Quoted 1 line

Ok, I re-based and applied the libsepol patch, ran the memfd tests (which passed), and confirmed that the WARN_ON() didn't trigger.

Quoted 27 lines
Quoted 27 lines
Fixes 084f547bd8e3 ("memfd,selinux: call security_inode_init_security_anon()")
---
 security/selinux/hooks.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
security/selinux/hooks.c +3 -3
index b2ad83353c17..2b685f9dd61d 100644
@@ -2320,8 +2320,9 @@ static int selinux_bprm_creds_for_exec(struct linux_binprm *bprm)
        new_tsec = selinux_cred(bprm->cred);
        isec = inode_security(inode);
 
-       if (isec->sclass != SECCLASS_FILE && isec->sclass != SECCLASS_MEMFD_FILE)
-               return -EPERM;
+       if (WARN_ON(isec->sclass != SECCLASS_FILE &&
+                   isec->sclass != SECCLASS_MEMFD_FILE))
+               return -EACCES;
 
        /* Default to the current task SID. */
        new_tsec->sid = old_tsec->sid;
--

2.51.0

author maintainer
#7 lore raw
In reply to Stephen Smalley
Quoted 11 lines · Stephen Smalley
Quoted 9 lines · Paul Moore

A prior commit, see the 'Fixes:' tag below, added support for a new object class, memfd_file. As part of that change, support for the new object class was added to selinux_bprm_creds_for_exec() to facilitate execution of memfd_file objects using fexecvc(2), or similar. This patch adjusts some of the sanity checking added in that commit to avoid a "silent denial" in the case of a kernel bug as well as return -EACCES instead of -EPERM so that we can more easily distinguish between a permission denial and a fault in the code.

Quoted 5 lines

Technically, this doesn't make it easier to distinguish because we usually return -EACCES from avc_has_perm() and friends, but return -EPERM for capability denials and in certain other cases (not always clear why, arguably a bug unless we were just replicating the error number for some existing check that also returned -EPERM).

It's awfully fuzzy from my perspective.

Quoted 7 lines

My
suggestion to use -EACCES was because that is more consistent with how we report denials outside of capability checks.
To actually test this, would need an updated libsepol patch that deals with the fact that the policy capability number changed on merge, or re-basing the original patch on top. Otherwise,

To be honest, this isn't the sort of discussion I like to see for patches that are merged in the -rc5 time frame, if we're merging stuff at this point in the dev cycle we should be past uncertainty like this. I'm obviously not going to merge this patch and I'm going to drop Thiébaud's patch from selinux/dev too so we can sort this out.

Thiébaud, go ahead and take the WARN_ON() change for your next revision of the patch, and let's continue the discussion on the proper return code.

Signature · 1 line
paul-moore.com
maintainer
#8 lore raw
Quoted 30 lines · Paul Moore
Quoted 11 lines · Stephen Smalley
Quoted 9 lines · Paul Moore

A prior commit, see the 'Fixes:' tag below, added support for a new object class, memfd_file. As part of that change, support for the new object class was added to selinux_bprm_creds_for_exec() to facilitate execution of memfd_file objects using fexecvc(2), or similar. This patch adjusts some of the sanity checking added in that commit to avoid a "silent denial" in the case of a kernel bug as well as return -EACCES instead of -EPERM so that we can more easily distinguish between a permission denial and a fault in the code.

Quoted 5 lines

Technically, this doesn't make it easier to distinguish because we usually return -EACCES from avc_has_perm() and friends, but return -EPERM for capability denials and in certain other cases (not always clear why, arguably a bug unless we were just replicating the error number for some existing check that also returned -EPERM).

It's awfully fuzzy from my perspective.

Quoted 7 lines

My
suggestion to use -EACCES was because that is more consistent with how we report denials outside of capability checks.
To actually test this, would need an updated libsepol patch that deals with the fact that the policy capability number changed on merge, or re-basing the original patch on top. Otherwise,

Quoted 5 lines

To be honest, this isn't the sort of discussion I like to see for patches that are merged in the -rc5 time frame, if we're merging stuff at this point in the dev cycle we should be past uncertainty like this. I'm obviously not going to merge this patch and I'm going to drop Thiébaud's patch from selinux/dev too so we can sort this out.

Not sure it warrants reverting Thiebaud's patch. I was fine ack'ing that as is. I just thought we might want to follow up with something to improve the error handling here, which can be done anytime IMHO.

Quoted 7 lines

Thiébaud, go ahead and take the WARN_ON() change for your next revision of the patch, and let's continue the discussion on the proper return code.

--
paul-moore.com

maintainer
#9 lore raw
Quoted 38 lines · Stephen Smalley
Quoted 30 lines · Paul Moore
Quoted 11 lines · Stephen Smalley
Quoted 9 lines · Paul Moore

A prior commit, see the 'Fixes:' tag below, added support for a new object class, memfd_file. As part of that change, support for the new object class was added to selinux_bprm_creds_for_exec() to facilitate execution of memfd_file objects using fexecvc(2), or similar. This patch adjusts some of the sanity checking added in that commit to avoid a "silent denial" in the case of a kernel bug as well as return -EACCES instead of -EPERM so that we can more easily distinguish between a permission denial and a fault in the code.

Quoted 5 lines

Technically, this doesn't make it easier to distinguish because we usually return -EACCES from avc_has_perm() and friends, but return -EPERM for capability denials and in certain other cases (not always clear why, arguably a bug unless we were just replicating the error number for some existing check that also returned -EPERM).

It's awfully fuzzy from my perspective.

Quoted 7 lines

My
suggestion to use -EACCES was because that is more consistent with how we report denials outside of capability checks.
To actually test this, would need an updated libsepol patch that deals with the fact that the policy capability number changed on merge, or re-basing the original patch on top. Otherwise,

Quoted 5 lines

To be honest, this isn't the sort of discussion I like to see for patches that are merged in the -rc5 time frame, if we're merging stuff at this point in the dev cycle we should be past uncertainty like this. I'm obviously not going to merge this patch and I'm going to drop Thiébaud's patch from selinux/dev too so we can sort this out.

Quoted 3 lines

Not sure it warrants reverting Thiebaud's patch. I was fine ack'ing that as is. I just thought we might want to follow up with something to improve the error handling here, which can be done anytime IMHO.

And if we revert his kernel patch, I'll have to likewise revert the libsepol patch, and the policy capability number might change yet again before it lands.

author maintainer
#10 lore raw
Quoted 40 lines · Stephen Smalley
Quoted 38 lines · Stephen Smalley
Quoted 35 lines · Paul Moore
Quoted 11 lines · Stephen Smalley
Quoted 9 lines · Paul Moore

A prior commit, see the 'Fixes:' tag below, added support for a new object class, memfd_file. As part of that change, support for the new object class was added to selinux_bprm_creds_for_exec() to facilitate execution of memfd_file objects using fexecvc(2), or similar. This patch adjusts some of the sanity checking added in that commit to avoid a "silent denial" in the case of a kernel bug as well as return -EACCES instead of -EPERM so that we can more easily distinguish between a permission denial and a fault in the code.

Quoted 5 lines

Technically, this doesn't make it easier to distinguish because we usually return -EACCES from avc_has_perm() and friends, but return -EPERM for capability denials and in certain other cases (not always clear why, arguably a bug unless we were just replicating the error number for some existing check that also returned -EPERM).

It's awfully fuzzy from my perspective.

Quoted 7 lines

My
suggestion to use -EACCES was because that is more consistent with how we report denials outside of capability checks.
To actually test this, would need an updated libsepol patch that deals with the fact that the policy capability number changed on merge, or re-basing the original patch on top. Otherwise,

To be honest, this isn't the sort of discussion I like to see for patches that are merged in the -rc5 time frame, if we're merging stuff at this point in the dev cycle we should be past uncertainty like this. I'm obviously not going to merge this patch and I'm going to drop Thiébaud's patch from selinux/dev too so we can sort this out.

Quoted 7 lines
Quoted 3 lines

Not sure it warrants reverting Thiebaud's patch. I was fine ack'ing that as is. I just thought we might want to follow up with something to improve the error handling here, which can be done anytime IMHO.

And if we revert his kernel patch, I'll have to likewise revert the libsepol patch, and the policy capability number might change yet again before it lands.

Yep.

Signature · 1 line
paul-moore.com
maintainer
#11 lore raw
Quoted 47 lines · Paul Moore
Quoted 44 lines · Stephen Smalley
Quoted 41 lines · Stephen Smalley
Quoted 30 lines · Paul Moore
Quoted 11 lines · Stephen Smalley
Quoted 9 lines · Paul Moore

A prior commit, see the 'Fixes:' tag below, added support for a new object class, memfd_file. As part of that change, support for the new object class was added to selinux_bprm_creds_for_exec() to facilitate execution of memfd_file objects using fexecvc(2), or similar. This patch adjusts some of the sanity checking added in that commit to avoid a "silent denial" in the case of a kernel bug as well as return -EACCES instead of -EPERM so that we can more easily distinguish between a permission denial and a fault in the code.

Quoted 5 lines

Technically, this doesn't make it easier to distinguish because we usually return -EACCES from avc_has_perm() and friends, but return -EPERM for capability denials and in certain other cases (not always clear why, arguably a bug unless we were just replicating the error number for some existing check that also returned -EPERM).

It's awfully fuzzy from my perspective.

Quoted 7 lines

My
suggestion to use -EACCES was because that is more consistent with how we report denials outside of capability checks.
To actually test this, would need an updated libsepol patch that deals with the fact that the policy capability number changed on merge, or re-basing the original patch on top. Otherwise,

Quoted 5 lines

To be honest, this isn't the sort of discussion I like to see for patches that are merged in the -rc5 time frame, if we're merging stuff at this point in the dev cycle we should be past uncertainty like this. I'm obviously not going to merge this patch and I'm going to drop Thiébaud's patch from selinux/dev too so we can sort this out.

Not sure it warrants reverting Thiebaud's patch. I was fine ack'ing that as is. I just thought we might want to follow up with something to improve the error handling here, which can be done anytime IMHO.

Quoted 5 lines
Quoted 3 lines

And if we revert his kernel patch, I'll have to likewise revert the libsepol patch, and the policy capability number might change yet again before it lands.

Yep.

Bummer. Me and my big mouth. Apologies to all.
Revert coming up...
On a different note, taking a quick look at POSIX.1 definitions of EPERM and EACCES makes me think we got it all wrong originally and should have been returning EPERM most places (except for file access checks, maybe). But changing the existing ones now could create havoc for userspace.

author maintainer
#12 lore raw
Quoted 47 lines · Stephen Smalley
Quoted 46 lines · Paul Moore
Quoted 44 lines · Stephen Smalley
Quoted 41 lines · Stephen Smalley
Quoted 30 lines · Paul Moore
Quoted 11 lines · Stephen Smalley
Quoted 9 lines · Paul Moore

A prior commit, see the 'Fixes:' tag below, added support for a new object class, memfd_file. As part of that change, support for the new object class was added to selinux_bprm_creds_for_exec() to facilitate execution of memfd_file objects using fexecvc(2), or similar. This patch adjusts some of the sanity checking added in that commit to avoid a "silent denial" in the case of a kernel bug as well as return -EACCES instead of -EPERM so that we can more easily distinguish between a permission denial and a fault in the code.

Quoted 5 lines

Technically, this doesn't make it easier to distinguish because we usually return -EACCES from avc_has_perm() and friends, but return -EPERM for capability denials and in certain other cases (not always clear why, arguably a bug unless we were just replicating the error number for some existing check that also returned -EPERM).

It's awfully fuzzy from my perspective.

Quoted 7 lines

My
suggestion to use -EACCES was because that is more consistent with how we report denials outside of capability checks.
To actually test this, would need an updated libsepol patch that deals with the fact that the policy capability number changed on merge, or re-basing the original patch on top. Otherwise,

Quoted 5 lines

To be honest, this isn't the sort of discussion I like to see for patches that are merged in the -rc5 time frame, if we're merging stuff at this point in the dev cycle we should be past uncertainty like this. I'm obviously not going to merge this patch and I'm going to drop Thiébaud's patch from selinux/dev too so we can sort this out.

Not sure it warrants reverting Thiebaud's patch. I was fine ack'ing that as is. I just thought we might want to follow up with something to improve the error handling here, which can be done anytime IMHO.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

And if we revert his kernel patch, I'll have to likewise revert the libsepol patch, and the policy capability number might change yet again before it lands.

Yep.

Bummer. Me and my big mouth. Apologies to all.

I really don't want the take away from this to be that speaking up about potential issues is a bad thing. It's far better to address issues, even if they ultimately turn out to be nothing, *before* they go up to Linus' tree rather than afterwards. If folks start holding back their comments for fear of a patch being held for revision, rejected, dropped, or reverted, then we potentially set ourselves up for failure in the future with ourselves, our users, and the kernel development community as a whole; all of those possibilities are far worse than what we are dealing with now.

If anything, the fault in this particular case was mine for not reviewing the patch as thoroughly as I should have done; I was trying to make sure we got things merged before the end of -rc5 and in my haste I rushed through the review. My apologies on that, I was impatient and it caused confusion and extra work for everyone.

Quoted 1 line

Revert coming up...

This is something that might be worth a more general discussion among the userspace folks, but moving forward it might be good policy to not merge userspace changes that rely on kernel API magic numbers until the associated kernel patch ends up in a tagged release from Linus. Of course one could always merge the patches into a "dev", "staging", or topic branch for ease of testing and later merge it into the default branch. Just a thought.

Quoted 5 lines

On a different note, taking a quick look at POSIX.1 definitions of EPERM and EACCES makes me think we got it all wrong originally and should have been returning EPERM most places (except for file access checks, maybe). But changing the existing ones now could create havoc for userspace.

Yes, what we have in the kernel now is what we need to stick with moving forward. While consistency with POSIX is a nice goal, consistency with the existing kernel code is the most important thing.

Signature · 1 line
paul-moore.com
#13 lore raw
Quoted 24 lines · Paul Moore
Quoted 21 lines · Stephen Smalley
Quoted 20 lines · Paul Moore
Quoted 18 lines · Stephen Smalley
Quoted 16 lines · Stephen Smalley
Quoted 14 lines · Paul Moore
Quoted 11 lines · Stephen Smalley
Quoted 9 lines · Paul Moore

A prior commit, see the 'Fixes:' tag below, added support for a new object class, memfd_file. As part of that change, support for the new object class was added to selinux_bprm_creds_for_exec() to facilitate execution of memfd_file objects using fexecvc(2), or similar. This patch adjusts some of the sanity checking added in that commit to avoid a "silent denial" in the case of a kernel bug as well as return -EACCES instead of -EPERM so that we can more easily distinguish between a permission denial and a fault in the code.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

Technically, this doesn't make it easier to distinguish because we usually return -EACCES from avc_has_perm() and friends, but return -EPERM for capability denials and in certain other cases (not always clear why, arguably a bug unless we were just replicating the error number for some existing check that also returned -EPERM).

It's awfully fuzzy from my perspective.

Stephen, from re-reading your messages, I am not sure which option you prefer at this stage. Are you leaning back towards -EPERM?

An alternative here would be -EOPNOTSUPP, this would be more explicit for userland on the root cause. There are similar usages in hooks.c (see selinux_lsm_getattr for instance).

Quoted 37 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 9 lines
Quoted 8 lines

My
suggestion to use -EACCES was because that is more consistent with how we report denials outside of capability checks.
To actually test this, would need an updated libsepol patch that deals with the fact that the policy capability number changed on merge, or re-basing the original patch on top. Otherwise,

Quoted 5 lines

To be honest, this isn't the sort of discussion I like to see for patches that are merged in the -rc5 time frame, if we're merging stuff at this point in the dev cycle we should be past uncertainty like this. I'm obviously not going to merge this patch and I'm going to drop Thiébaud's patch from selinux/dev too so we can sort this out.

Not sure it warrants reverting Thiebaud's patch. I was fine ack'ing that as is. I just thought we might want to follow up with something to improve the error handling here, which can be done anytime IMHO.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

And if we revert his kernel patch, I'll have to likewise revert the libsepol patch, and the policy capability number might change yet again before it lands.

Yep.

Bummer. Me and my big mouth. Apologies to all.

I really don't want the take away from this to be that speaking up about potential issues is a bad thing. It's far better to address issues, even if they ultimately turn out to be nothing, *before* they go up to Linus' tree rather than afterwards. If folks start holding back their comments for fear of a patch being held for revision, rejected, dropped, or reverted, then we potentially set ourselves up for failure in the future with ourselves, our users, and the kernel development community as a whole; all of those possibilities are far worse than what we are dealing with now.

Quoted 6 lines

If anything, the fault in this particular case was mine for not reviewing the patch as thoroughly as I should have done; I was trying to make sure we got things merged before the end of -rc5 and in my haste I rushed through the review. My apologies on that, I was impatient and it caused confusion and extra work for everyone.

No worries at all.

Quoted 22 lines
Quoted 1 line

Revert coming up...

This is something that might be worth a more general discussion among the userspace folks, but moving forward it might be good policy to not merge userspace changes that rely on kernel API magic numbers until the associated kernel patch ends up in a tagged release from Linus. Of course one could always merge the patches into a "dev", "staging", or topic branch for ease of testing and later merge it into the default branch. Just a thought.

Quoted 5 lines

On a different note, taking a quick look at POSIX.1 definitions of EPERM and EACCES makes me think we got it all wrong originally and should have been returning EPERM most places (except for file access checks, maybe). But changing the existing ones now could create havoc for userspace.

Yes, what we have in the kernel now is what we need to stick with moving forward. While consistency with POSIX is a nice goal, consistency with the existing kernel code is the most important thing.

--
paul-moore.com

maintainer
#14 lore raw
Quoted 32 lines · Thiébaud Weksteen
Quoted 30 lines · Paul Moore
Quoted 27 lines · Stephen Smalley
Quoted 26 lines · Paul Moore
Quoted 24 lines · Stephen Smalley
Quoted 22 lines · Stephen Smalley
Quoted 20 lines · Paul Moore
Quoted 16 lines · Stephen Smalley
Quoted 9 lines · Paul Moore

A prior commit, see the 'Fixes:' tag below, added support for a new object class, memfd_file. As part of that change, support for the new object class was added to selinux_bprm_creds_for_exec() to facilitate execution of memfd_file objects using fexecvc(2), or similar. This patch adjusts some of the sanity checking added in that commit to avoid a "silent denial" in the case of a kernel bug as well as return -EACCES instead of -EPERM so that we can more easily distinguish between a permission denial and a fault in the code.

Technically, this doesn't make it easier to distinguish because we usually return -EACCES from avc_has_perm() and friends, but return -EPERM for capability denials and in certain other cases (not always clear why, arguably a bug unless we were just replicating the error number for some existing check that also returned -EPERM).

Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

It's awfully fuzzy from my perspective.

Stephen, from re-reading your messages, I am not sure which option you prefer at this stage. Are you leaning back towards -EPERM?

An alternative here would be -EOPNOTSUPP, this would be more explicit for userland on the root cause. There are similar usages in hooks.c (see selinux_lsm_getattr for instance).

At the end of the day, I don't strongly care and only Paul's opinion matters for final merge. Some arguments for each of the different options:
1. -EACCES: Consistent with the majority of the SELinux code, particularly all avc_has_perm() calls. WRT POSIX.1, it seems to be primarily for file access checks but broadly can be viewed as "access denied to an object", which is the majority of the SELinux checks. In the case of this particular LSM hook and system call, we are dealing with a file object, and hence -EACCES could be viewed as appropriate to this check.
2. -EPERM: Used for several cases within this hook function already, most likely due to checks that mirrored corresponding Linux checks in the core kernel that were also returning -EPERM. WRT POSIX.1, it seems to be for any permission check other than file access checks but broadly can be viewed as "operation not permitted for this process" with no object in view. In the case of this particular LSM hook and system call, we are already returning -EPERM for several other cases, and hence -EPERM could be viewed as appropriate to this check.
3. -EOPNOTSUPP: Used by other SELinux hooks already. WRT POSIX.1, it seems to be only used for sockets, but on Linux, it has the same value as ENOTSUP and can broadly be viewed as "operation not supported". In the case of this particular LSM hook and system call, I don't see any existing uses of this error value, which could be good or bad depending on one's perspective (good: easily distinguished from any other cause; bad: not expected by userspace on execve, not documented in the execve man page).

As far as I am concerned, feel free to pick any of the above and post a patch with it along with the corresponding rationale, and Paul can tell you if he wants something else.

author maintainer
#15 lore raw
Quoted 10 lines · Stephen Smalley

At the end of the day, I don't strongly care and only Paul's opinion matters for final merge. Some arguments for each of the different options:
1. -EACCES: Consistent with the majority of the SELinux code, particularly all avc_has_perm() calls. WRT POSIX.1, it seems to be primarily for file access checks but broadly can be viewed as "access denied to an object", which is the majority of the SELinux checks. In the case of this particular LSM hook and system call, we are dealing with a file object, and hence -EACCES could be viewed as appropriate to this check.

Let's go with -EACCES, as Stephen has already mentioned, it's consistent with the vast majority of SELinux return codes where access has been denied, and while we can debate the merits of EACCES over EPERM as it relates to the presence of a clearly defined object, or the EPERM usage elsewhere in selinux_bprm_creds_for_exec(), at the end of it all I don't think there is going to be a clear choice here so let's go with the most common SELinux error code.

... and don't forget the WARN_ON() :)

Quoted 20 lines

2. -EPERM: Used for several cases within this hook function already, most likely due to checks that mirrored corresponding Linux checks in the core kernel that were also returning -EPERM. WRT POSIX.1, it seems to be for any permission check other than file access checks but broadly can be viewed as "operation not permitted for this process" with no object in view. In the case of this particular LSM hook and system call, we are already returning -EPERM for several other cases, and hence -EPERM could be viewed as appropriate to this check.
3. -EOPNOTSUPP: Used by other SELinux hooks already. WRT POSIX.1, it seems to be only used for sockets, but on Linux, it has the same value as ENOTSUP and can broadly be viewed as "operation not supported". In the case of this particular LSM hook and system call, I don't see any existing uses of this error value, which could be good or bad depending on one's perspective (good: easily distinguished from any other cause; bad: not expected by userspace on execve, not documented in the execve man page).

As far as I am concerned, feel free to pick any of the above and post a patch with it along with the corresponding rationale, and Paul can tell you if he wants something else.

Signature · 1 line
paul-moore.com
#16 lore raw
Quoted 14 lines · Paul Moore
Quoted 10 lines · Stephen Smalley

At the end of the day, I don't strongly care and only Paul's opinion matters for final merge. Some arguments for each of the different options:
1. -EACCES: Consistent with the majority of the SELinux code, particularly all avc_has_perm() calls. WRT POSIX.1, it seems to be primarily for file access checks but broadly can be viewed as "access denied to an object", which is the majority of the SELinux checks. In the case of this particular LSM hook and system call, we are dealing with a file object, and hence -EACCES could be viewed as appropriate to this check.

Quoted 7 lines

Let's go with -EACCES, as Stephen has already mentioned, it's consistent with the vast majority of SELinux return codes where access has been denied, and while we can debate the merits of EACCES over EPERM as it relates to the presence of a clearly defined object, or the EPERM usage elsewhere in selinux_bprm_creds_for_exec(), at the end of it all I don't think there is going to be a clear choice here so let's go with the most common SELinux error code.

Great, thanks for helping by making a call here Paul. Respinning a patch now.

Quoted 19 lines

... and don't forget the WARN_ON() :)

Quoted 16 lines

2. -EPERM: Used for several cases within this hook function already, most likely due to checks that mirrored corresponding Linux checks in the core kernel that were also returning -EPERM. WRT POSIX.1, it seems to be for any permission check other than file access checks but broadly can be viewed as "operation not permitted for this process" with no object in view. In the case of this particular LSM hook and system call, we are already returning -EPERM for several other cases, and hence -EPERM could be viewed as appropriate to this check.
3. -EOPNOTSUPP: Used by other SELinux hooks already. WRT POSIX.1, it seems to be only used for sockets, but on Linux, it has the same value as ENOTSUP and can broadly be viewed as "operation not supported". In the case of this particular LSM hook and system call, I don't see any existing uses of this error value, which could be good or bad depending on one's perspective (good: easily distinguished from any other cause; bad: not expected by userspace on execve, not documented in the execve man page).

Thanks for the clear comparison Stephen.

Quoted 7 lines
Quoted 4 lines

As far as I am concerned, feel free to pick any of the above and post a patch with it along with the corresponding rationale, and Paul can tell you if he wants something else.

--
paul-moore.com

author maintainer
#17 lore raw
Quoted 22 lines · Thiébaud Weksteen
Quoted 13 lines · Paul Moore
Quoted 10 lines · Stephen Smalley

At the end of the day, I don't strongly care and only Paul's opinion matters for final merge. Some arguments for each of the different options:
1. -EACCES: Consistent with the majority of the SELinux code, particularly all avc_has_perm() calls. WRT POSIX.1, it seems to be primarily for file access checks but broadly can be viewed as "access denied to an object", which is the majority of the SELinux checks. In the case of this particular LSM hook and system call, we are dealing with a file object, and hence -EACCES could be viewed as appropriate to this check.

Quoted 7 lines

Let's go with -EACCES, as Stephen has already mentioned, it's consistent with the vast majority of SELinux return codes where access has been denied, and while we can debate the merits of EACCES over EPERM as it relates to the presence of a clearly defined object, or the EPERM usage elsewhere in selinux_bprm_creds_for_exec(), at the end of it all I don't think there is going to be a clear choice here so let's go with the most common SELinux error code.

Quoted 1 line

Great, thanks for helping by making a call here Paul. Respinning a patch now.

Thanks for your patience and persistence with this.

Signature · 1 line
paul-moore.com
author maintainer
#18 lore raw
In reply to Stephen Smalley
Quoted 36 lines · Stephen Smalley
Quoted 29 lines · Paul Moore
Quoted 11 lines · Stephen Smalley
Quoted 9 lines · Paul Moore

A prior commit, see the 'Fixes:' tag below, added support for a new object class, memfd_file. As part of that change, support for the new object class was added to selinux_bprm_creds_for_exec() to facilitate execution of memfd_file objects using fexecvc(2), or similar. This patch adjusts some of the sanity checking added in that commit to avoid a "silent denial" in the case of a kernel bug as well as return -EACCES instead of -EPERM so that we can more easily distinguish between a permission denial and a fault in the code.

Quoted 5 lines

Technically, this doesn't make it easier to distinguish because we usually return -EACCES from avc_has_perm() and friends, but return -EPERM for capability denials and in certain other cases (not always clear why, arguably a bug unless we were just replicating the error number for some existing check that also returned -EPERM).

It's awfully fuzzy from my perspective.

Quoted 7 lines

My
suggestion to use -EACCES was because that is more consistent with how we report denials outside of capability checks.
To actually test this, would need an updated libsepol patch that deals with the fact that the policy capability number changed on merge, or re-basing the original patch on top. Otherwise,

Quoted 5 lines

To be honest, this isn't the sort of discussion I like to see for patches that are merged in the -rc5 time frame, if we're merging stuff at this point in the dev cycle we should be past uncertainty like this. I'm obviously not going to merge this patch and I'm going to drop Thiébaud's patch from selinux/dev too so we can sort this out.

Quoted 3 lines

Not sure it warrants reverting Thiebaud's patch. I was fine ack'ing that as is. I just thought we might want to follow up with something to improve the error handling here, which can be done anytime IMHO.

I believe it does, the tree on kernel.org should be updated now.

I agree that at the very least we should have a better discussion/consensus about the error handling, and that is something that should happen before we send the patch up to Linus.

Signature · 1 line
paul-moore.com