lkml.org 
[lkml]   [2020]   [May]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Date
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@xmission.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
\
 
 \ /
  Last update: 2020-05-28 17:54    [W:0.403 / U:0.152 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site