[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87y2pcvz3b.fsf_-_@x220.int.ebiederm.org>
Date: Thu, 28 May 2020 10:49:44 -0500
From: ebiederm@...ssion.com (Eric W. Biederman)
To: <linux-kernel@...r.kernel.org>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
Oleg Nesterov <oleg@...hat.com>, Jann Horn <jannh@...gle.com>,
Kees Cook <keescook@...omium.org>,
Greg Ungerer <gerg@...ux-m68k.org>,
Rob Landley <rob@...dley.net>,
Bernd Edlinger <bernd.edlinger@...mail.de>,
<linux-fsdevel@...r.kernel.org>, Al Viro <viro@...IV.linux.org.uk>,
Alexey Dobriyan <adobriyan@...il.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Casey Schaufler <casey@...aufler-ca.com>,
linux-security-module@...r.kernel.org,
James Morris <jmorris@...ei.org>,
"Serge E. Hallyn" <serge@...lyn.com>,
Andy Lutomirski <luto@...capital.net>
Subject: [PATCH 09/11] exec: In bprm_fill_uid only set per_clear when honoring suid or sgid
It makes no sense to set active_per_clear when the kernel decides not
to honor the executables setuid or or setgid bits. Instead set
active_per_clear when the kernel actually decides to honor the suid or
sgid permission bits of an executable.
As far as I can tell this was the intended behavior but with the
ptrace logic hiding out in security/commcap.c:cap_bprm_apply_creds I
believe it was just overlooked that the setuid or setgid operation
could be cancelled.
History Tree: git://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git
Fixes: 1bb0fa189c6a ("[PATCH] NX: clean up legacy binary support")
Signed-off-by: "Eric W. Biederman" <ebiederm@...ssion.com>
---
fs/exec.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/fs/exec.c b/fs/exec.c
index af108ecf9632..347dade4bc54 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1634,15 +1634,16 @@ static void bprm_fill_uid(struct linux_binprm *bprm)
need_cap = bprm->unsafe & LSM_UNSAFE_SHARE ||
!ptracer_capable(current, new->user_ns);
- if (mode & S_ISUID) {
+ if ((mode & S_ISUID) &&
+ (!need_cap || ns_capable(new->user_ns, CAP_SETUID))) {
bprm->per_clear = 1;
- if (!need_cap || ns_capable(new->user_ns, CAP_SETUID))
- new->suid = new->fsuid = new->euid = uid;
+ new->suid = new->fsuid = new->euid = uid;
}
- if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
+
+ if (((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) &&
+ (!need_cap || ns_capable(new->user_ns, CAP_SETGID))) {
bprm->per_clear = 1;
- if (!need_cap || ns_capable(new->user_ns, CAP_SETGID))
- new->sgid = new->fsgid = new->egid = gid;
+ new->sgid = new->fsgid = new->egid = gid;
}
after_setid:
--
2.25.0
Powered by blists - more mailing lists