exec: In bprm_fill_uid remove unnecessary no new privs check

Started by Eric W. Biederman on May 28, 2020

Subsystems (3)

Maintainers (4)

DORMANTno replies

open the first message on its own page

Message details and related content
When the no new privs code was added[1], a test was added to
cap_bprm_set_creds to ensure that the credential change were always
reverted if no new privs was set.

That test has been refactored into a test to not make the credential
change in bprm_fill_uid when no new privs is set.  Remove that
unncessary test as it can now been seen by a quick inspection that
execution can never make it to the test with no new privs set.

The same change[1] also added a test that guaranteed the credentials
would never change when no_new_privs was set, so the test I am removing
was never necessary but historically that was far from obvious.

[1]: 259e5e6c75a9 ("Add PR_{GET,SET}_NO_NEW_PRIVS to prevent execve from granting privs")
Signed-off-by: "Eric W. Biederman" <redacted>
---
 fs/exec.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/fs/exec.c b/fs/exec.c
index 8dd7254931dc..af108ecf9632 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1636,16 +1636,12 @@ static void bprm_fill_uid(struct linux_binprm *bprm)
 
 	if (mode & S_ISUID) {
 		bprm->per_clear = 1;
-		if (!need_cap ||
-		    (ns_capable(new->user_ns, CAP_SETUID) &&
-		     !(bprm->unsafe & LSM_UNSAFE_NO_NEW_PRIVS)))
+		if (!need_cap || ns_capable(new->user_ns, CAP_SETUID))
 			new->suid = new->fsuid = new->euid = uid;
 	}
 	if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
 		bprm->per_clear = 1;
-		if (!need_cap ||
-		    (ns_capable(new->user_ns, CAP_SETGID) &&
-		     !(bprm->unsafe & LSM_UNSAFE_NO_NEW_PRIVS)))
+		if (!need_cap || ns_capable(new->user_ns, CAP_SETGID))
 			new->sgid = new->fsgid = new->egid = gid;
 	}
 
-- 
2.25.0
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help