linux/arch/s390
Hugh Dickins 1be7107fbe mm: larger stack guard gap, between vmas
Stack guard page is a useful feature to reduce a risk of stack smashing
into a different mapping. We have been using a single page gap which
is sufficient to prevent having stack adjacent to a different mapping.
But this seems to be insufficient in the light of the stack usage in
userspace. E.g. glibc uses as large as 64kB alloca() in many commonly
used functions. Others use constructs liks gid_t buffer[NGROUPS_MAX]
which is 256kB or stack strings with MAX_ARG_STRLEN.

This will become especially dangerous for suid binaries and the default
no limit for the stack size limit because those applications can be
tricked to consume a large portion of the stack and a single glibc call
could jump over the guard page. These attacks are not theoretical,
unfortunatelly.

Make those attacks less probable by increasing the stack guard gap
to 1MB (on systems with 4k pages; but make it depend on the page size
because systems with larger base pages might cap stack allocations in
the PAGE_SIZE units) which should cover larger alloca() and VLA stack
allocations. It is obviously not a full fix because the problem is
somehow inherent, but it should reduce attack space a lot.

One could argue that the gap size should be configurable from userspace,
but that can be done later when somebody finds that the new 1MB is wrong
for some special case applications.  For now, add a kernel command line
option (stack_guard_gap) to specify the stack gap size (in page units).

Implementation wise, first delete all the old code for stack guard page:
because although we could get away with accounting one extra page in a
stack vma, accounting a larger gap can break userspace - case in point,
a program run with "ulimit -S -v 20000" failed when the 1MB gap was
counted for RLIMIT_AS; similar problems could come with RLIMIT_MLOCK
and strict non-overcommit mode.

Instead of keeping gap inside the stack vma, maintain the stack guard
gap as a gap between vmas: using vm_start_gap() in place of vm_start
(or vm_end_gap() in place of vm_end if VM_GROWSUP) in just those few
places which need to respect the gap - mainly arch_get_unmapped_area(),
and and the vma tree's subtree_gap support for that.

Original-patch-by: Oleg Nesterov <oleg@redhat.com>
Original-patch-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Hugh Dickins <hughd@google.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Tested-by: Helge Deller <deller@gmx.de> # parisc
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-19 21:50:20 +08:00
..
appldata sched/headers: Move task statistics APIs from <linux/sched.h> to <linux/sched/stat.h> 2017-03-03 01:43:43 +01:00
boot s390/decompressor: fix initrd corruption caused by bss clear 2017-03-22 08:21:20 +01:00
configs s390: update defconfig 2017-06-08 15:53:48 +02:00
crypto s390/crypt: use the correct module alias for paes_s390. 2017-04-26 16:52:57 +02:00
hypfs s390: hypfs: make inode explicitly non-modular 2016-10-31 17:55:40 +01:00
include KVM: s390: Fix for master (4.12) 2017-06-08 16:35:18 +02:00
kernel s390/kvm: do not rely on the ILC on kvm host protection fauls 2017-05-17 12:34:03 +02:00
kvm KVM: s390: fix ais handling vs cpu model 2017-05-31 19:54:49 +02:00
lib s390/uaccess: use sane length for __strncpy_from_user() 2017-05-09 10:43:24 +02:00
mm mm: larger stack guard gap, between vmas 2017-06-19 21:50:20 +08:00
net s390: use set_memory.h header 2017-05-08 17:15:13 -07:00
numa s390/numa: pin all possible cpus to nodes early 2016-12-07 07:23:33 +01:00
oprofile s390/dumpstack: restore reliable indicator for call traces 2016-10-17 14:44:30 +02:00
pci s390/pci: remove forward declaration 2017-04-05 07:35:24 +02:00
tools s390: kvm: Cpu model support for msa6, msa7 and msa8 2017-04-26 14:19:01 +02:00
Kbuild s390/crypto: Provide s390 specific arch random functionality. 2017-04-26 13:41:35 +02:00
Kconfig security/keys: add CONFIG_KEYS_COMPAT to Kconfig 2017-06-09 13:29:45 +10:00
Kconfig.debug Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux 2017-02-22 10:20:04 -08:00
Makefile
defconfig s390: update defconfig 2017-06-08 15:53:48 +02:00