linux/arch/parisc/kernel
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
..
.gitignore
asm-offsets.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
audit.c parisc: add kernel audit feature 2013-11-07 22:27:20 +01:00
binfmt_elf32.c fs/binfmt: Convert obsolete cputime type to nsecs 2017-02-01 09:13:51 +01:00
cache.c parisc: Optimize flush_kernel_vmap_range and invalidate_kernel_vmap_range 2017-03-15 20:57:33 +01:00
compat_audit.c parisc: add kernel audit feature 2013-11-07 22:27:20 +01:00
drivers.c treewide: Constify most dma_map_ops structures 2017-01-24 12:23:35 -05:00
entry.S scripts/spelling.txt: add regsiter -> register spelling mistake 2017-05-08 17:15:13 -07:00
firmware.c parisc: Enhance CPU detection code on PAT machines 2016-12-12 22:28:09 +01:00
ftrace.c ftrace: Add return address pointer to ftrace_ret_stack 2016-08-24 12:15:14 +02:00
hardware.c parisc: add serial ports of C8000/1GHz machine to hardware database 2014-07-13 15:51:58 +02:00
head.S parisc: Fix ftrace function tracer 2016-04-14 17:47:19 +02:00
hpmc.S parisc: Add cfi_startproc and cfi_endproc to assembly code 2016-10-05 22:54:40 +02:00
inventory.c parisc: Enhance CPU detection code on PAT machines 2016-12-12 22:28:09 +01:00
irq.c parisc: Filter out spurious interrupts in PA-RISC irq handler 2015-09-08 15:31:16 +02:00
Makefile parisc: Fix ftrace function tracer 2016-04-14 17:47:19 +02:00
module.c mm, vmalloc: use __GFP_HIGHMEM implicitly 2017-05-08 17:15:13 -07:00
pa7300lc.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/debug.h> 2017-03-02 08:42:34 +01:00
pacache.S parisc: Remove unnecessary TLB purges from flush_dcache_page_asm and flush_icache_page_asm 2016-12-07 09:01:21 +01:00
parisc_ksyms.c parisc: Clean up fixup routines for get_user()/put_user() 2017-03-29 21:50:36 +02:00
pci-dma.c treewide: Constify most dma_map_ops structures 2017-01-24 12:23:35 -05:00
pci.c parisc: Use generic pci_mmap_resource_range() 2017-04-20 08:47:47 -05:00
pdc_chassis.c parisc: single_open() leaks 2013-05-05 00:10:41 -04:00
pdc_cons.c parisc: don't use module_init for non-modular core pdc_cons code 2015-06-16 14:12:30 -04:00
perf_asm.S
perf_images.h
perf.c parisc: perf: Fix potential NULL pointer dereference 2017-03-18 17:24:43 +01:00
process.c parisc: Avoid stalled CPU warnings after system shutdown 2017-03-29 21:50:38 +02:00
processor.c parisc: Optimize timer interrupt function 2016-12-20 21:39:40 +01:00
ptrace.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
real2.S parisc: Add cfi_startproc and cfi_endproc to assembly code 2016-10-05 22:54:40 +02:00
setup.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/clock.h> 2017-03-02 08:42:27 +01:00
signal32.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
signal32.h constify copy_siginfo_to_user{,32}() 2013-11-09 00:16:29 -05:00
signal.c Merge branch 'parisc-4.11-1' of git://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux 2017-03-03 16:20:06 -08:00
smp.c sched/headers: Move task->mm handling methods to <linux/sched/mm.h> 2017-03-03 01:43:28 +01:00
stacktrace.c
sys_parisc32.c parisc: drop unused defines and header includes 2014-07-13 15:56:12 +02:00
sys_parisc.c mm: larger stack guard gap, between vmas 2017-06-19 21:50:20 +08:00
syscall_table.S parisc: Wire up statx system call 2017-03-15 21:11:27 +01:00
syscall.S parisc: Use LINUX_GATEWAY_ADDR define instead of hardcoded value 2016-11-02 23:06:38 +01:00
time.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/clock.h> 2017-03-02 08:42:27 +01:00
topology.c
traps.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/debug.h> 2017-03-02 08:42:34 +01:00
unaligned.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/debug.h> 2017-03-02 08:42:34 +01:00
unwind.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
vmlinux.lds.S parisc: Move exception table into read-only section 2016-10-09 13:29:07 +02:00