Skip to content

Commit 64701de

Browse files
committed
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>
1 parent 473d896 commit 64701de

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

fs/exec.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,18 @@ void setup_new_exec(struct linux_binprm * bprm)
13501350
*/
13511351
bprm->secureexec |= bprm->cap_elevated;
13521352

1353+
if (bprm->secureexec) {
1354+
/*
1355+
* For secureexec, reset the stack limit to sane default to
1356+
* avoid bad behavior from the prior rlimits. This has to
1357+
* happen before arch_pick_mmap_layout(), which examines
1358+
* RLIMIT_STACK, but after the point of no return to avoid
1359+
* needing to clean up the change on failure.
1360+
*/
1361+
if (current->signal->rlim[RLIMIT_STACK].rlim_cur > _STK_LIM)
1362+
current->signal->rlim[RLIMIT_STACK].rlim_cur = _STK_LIM;
1363+
}
1364+
13531365
arch_pick_mmap_layout(current->mm);
13541366

13551367
current->sas_ss_sp = current->sas_ss_size = 0;

0 commit comments

Comments
 (0)