diff mbox series

[08/11] exec: In bprm_fill_uid remove unnecessary no new privs check

Message ID 874ks0xdop.fsf_-_@x220.int.ebiederm.org (mailing list archive)
State New, archived
Headers show
Series [01/11] exec: Reduce bprm->per_clear to a single bit | expand

Commit Message

Eric W. Biederman May 28, 2020, 3:49 p.m. UTC
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" <ebiederm@xmission.com>
---
 fs/exec.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
diff mbox series

Patch

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;
 	}