summaryrefslogtreecommitdiffstats
path: root/fs/exec.c
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2017-07-18 15:25:35 -0700
committerKees Cook <keescook@chromium.org>2017-08-01 12:03:14 -0700
commit64701dee4178eb4a771b8b36cd86560f5b0e2460 (patch)
tree1a0012699f1c5ba4fb7909eb0db75aaf10168e7a /fs/exec.c
parent473d89639db0aaa0799616b397584ba4f58cd8e1 (diff)
downloadlinux-64701dee4178eb4a771b8b36cd86560f5b0e2460.tar.gz
linux-64701dee4178eb4a771b8b36cd86560f5b0e2460.tar.bz2
linux-64701dee4178eb4a771b8b36cd86560f5b0e2460.zip
exec: Use sane stack rlimit under secureexec
For a secureexec, before memory layout selection has happened, reset the stack rlimit to something sane to avoid the caller having control over the resulting layouts. $ ulimit -s 8192 $ ulimit -s unlimited $ /bin/sh -c 'ulimit -s' unlimited $ sudo /bin/sh -c 'ulimit -s' 8192 Cc: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: James Morris <james.l.morris@oracle.com> Acked-by: Serge Hallyn <serge@hallyn.com>
Diffstat (limited to 'fs/exec.c')
-rw-r--r--fs/exec.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/fs/exec.c b/fs/exec.c
index 3006c1c24304..3235cbd85efa 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1350,6 +1350,18 @@ void setup_new_exec(struct linux_binprm * bprm)
*/
bprm->secureexec |= bprm->cap_elevated;
+ if (bprm->secureexec) {
+ /*
+ * For secureexec, reset the stack limit to sane default to
+ * avoid bad behavior from the prior rlimits. This has to
+ * happen before arch_pick_mmap_layout(), which examines
+ * RLIMIT_STACK, but after the point of no return to avoid
+ * needing to clean up the change on failure.
+ */
+ if (current->signal->rlim[RLIMIT_STACK].rlim_cur > _STK_LIM)
+ current->signal->rlim[RLIMIT_STACK].rlim_cur = _STK_LIM;
+ }
+
arch_pick_mmap_layout(current->mm);
current->sas_ss_sp = current->sas_ss_size = 0;