android_kernel_samsung_msm8976/arch/x86/kernel
Hugh Dickins 1448dc70cd mm: larger stack guard gap, between vmas
commit 1be7107fbe18eed3e319a6c3e83c78254b693acb upstream.

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.

Change-Id: I899511079c5057ee5299ef1aff5ab8f0c77c740d
Original-patch-by: Oleg Nesterov <oleg@redhat.com>
Original-patch-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Hugh Dickins <hughd@google.com>
[wt: backport to 4.11: adjust context]
[wt: backport to 4.9: adjust context ; kernel doc was not in admin-guide]
[wt: backport to 4.4: adjust context ; drop ppc hugetlb_radix changes]
[wt: backport to 3.18: adjust context ; no FOLL_POPULATE ;
     s390 uses generic arch_get_unmapped_area()]
[wt: backport to 3.16: adjust context]
[wt: backport to 3.10: adjust context ; code logic in PARISC's
     arch_get_unmapped_area() wasn't found ; code inserted into
     expand_upwards() and expand_downwards() runs under anon_vma lock;
     changes for gup.c:faultin_page go to memory.c:__get_user_pages();
     included Hugh Dickins' fixes]
Signed-off-by: Willy Tarreau <w@1wt.eu>
2017-07-11 00:00:39 +00:00
..
acpi PM / sleep / x86: Fix crash on graph trace through x86 suspend 2016-03-09 15:31:54 -08:00
apic x86/apic: Serialize LVTT and TSC_DEADLINE writes 2015-10-22 14:37:49 -07:00
cpu perf/x86/intel: Fix PEBS data source interpretation on Nehalem/Westmere 2016-06-07 10:42:48 +02:00
kprobes ftrace/jprobes/x86: Fix conflict between jprobes and function graph tracing 2015-01-27 07:52:32 -08:00
.gitignore
alternative.c
amd_gart_64.c
amd_nb.c x86, amd_nb: Clarify F15h, model 30h GART and L3 support 2013-09-26 17:18:14 -07:00
apb_timer.c
aperture_64.c
apm_32.c
asm-offsets.c
asm-offsets_32.c
asm-offsets_64.c
audit_64.c
bootflag.c
check.c
cpuid.c
crash.c
crash_dump_32.c
crash_dump_64.c
devicetree.c of: Specify initrd location using 64-bit 2014-02-07 13:49:42 -08:00
doublefault_32.c
dumpstack.c x86_64: add KASan support 2015-05-04 14:03:57 -07:00
dumpstack_32.c
dumpstack_64.c x86_64, traps: Stop using IST for #SS 2014-12-06 15:05:46 -08:00
e820.c x86: avoid remapping data in parse_setup_data() 2013-10-18 07:45:48 -07:00
early-quirks.c x86: Adjust irq remapping quirk for older revisions of 5500/5520 chipsets 2014-04-26 17:15:34 -07:00
early_printk.c
entry_32.S x86, espfix: Make it possible to disable 16-bit support 2014-08-07 14:30:26 -07:00
entry_64.S x86/asm/entry/64: Remove a bogus 'ret_from_fork' optimization 2015-03-18 13:22:28 +01:00
espfix_64.c x86/espfix/xen: Fix allocation of pages for paravirt page tables 2014-08-07 14:30:27 -07:00
ftrace.c ftrace/x86: One more missing sync after fixup of function modification failure 2014-05-06 07:55:28 -07:00
head.c
head32.c
head64.c This is the 3.10.98 stable release 2017-04-18 17:17:24 +02:00
head_32.S x86/asm/irq: Stop relying on magic JMP behavior for early_idt_handlers 2016-02-25 11:57:49 -08:00
head_64.S This is the 3.10.98 stable release 2017-04-18 17:17:24 +02:00
hpet.c
hw_breakpoint.c
i386_ksyms_32.c
i387.c x86, fpu: Check tsk_used_math() in kernel_fpu_end() for eager FPU 2014-03-23 21:38:19 -07:00
i8237.c
i8253.c
i8259.c
io_delay.c
ioport.c x86/iopl: Fix iopl capability check on Xen PV 2016-06-07 10:42:44 +02:00
irq.c
irq_32.c
irq_64.c
irq_work.c
irqinit.c
jump_label.c
kdebugfs.c
kgdb.c
kvm.c x86, kvm: Clear paravirt_enabled on KVM guests for espfix32's benefit 2015-01-08 09:58:15 -08:00
kvmclock.c x86, kvm: Clear paravirt_enabled on KVM guests for espfix32's benefit 2015-01-08 09:58:15 -08:00
ldt.c x86, espfix: Make it possible to disable 16-bit support 2014-08-07 14:30:26 -07:00
machine_kexec_32.c
machine_kexec_64.c
Makefile x86_64: add KASan support 2015-05-04 14:03:57 -07:00
microcode_amd.c x86/microcode/amd: Tone down printk(), don't treat a missing firmware file as an error 2013-11-29 11:11:49 -08:00
microcode_core.c
microcode_core_early.c
microcode_intel.c
microcode_intel_early.c x86/microcode/intel: Guard against stack overflow in the loader 2015-07-03 19:48:09 -07:00
microcode_intel_lib.c
mmconf-fam10h_64.c
module.c x86, kaslr: randomize module base load address 2015-12-08 23:47:16 -08:00
mpparse.c
msr.c
nmi.c
nmi_selftest.c
paravirt-spinlocks.c
paravirt.c
paravirt_patch_32.c
paravirt_patch_64.c x86_64/entry/xen: Do not invoke espfix64 on Xen 2014-08-07 14:30:26 -07:00
pci-calgary_64.c
pci-dma.c x86: dma-mapping: fix GFP_ATOMIC macro usage 2014-03-06 21:30:08 -08:00
pci-iommu_table.c
pci-nommu.c
pci-swiotlb.c
pcspeaker.c
perf_regs.c
probe_roms.c
process.c Merge upstream linux-stable v3.10.28 into msm-3.10 2014-03-24 14:28:34 -07:00
process_32.c x86, flags: Rename X86_EFLAGS_BIT1 to X86_EFLAGS_FIXED 2014-11-14 08:47:54 -08:00
process_64.c x86/iopl/64: Properly context-switch IOPL on Xen PV 2016-06-07 10:42:43 +02:00
ptrace.c x86, x32, audit: Fix x32's AUDIT_ARCH wrt audit 2014-11-21 09:22:52 -08:00
pvclock.c
quirks.c x86/amd/numa: Fix northbridge quirk to assign correct NUMA node 2014-03-23 21:38:15 -07:00
reboot.c This is the 3.10.96 stable release 2017-04-18 17:16:02 +02:00
reboot_fixups_32.c
relocate_kernel_32.S
relocate_kernel_64.S
resource.c x86: don't exclude low BIOS area when allocating address space for non-PCI cards 2014-09-05 16:28:36 -07:00
rtc.c
setup.c This is the 3.10.94 stable release 2017-04-18 17:12:56 +02:00
setup_percpu.c
signal.c x86/signal: Fix restart_syscall number for x32 tasks 2016-01-28 21:49:28 -08:00
smp.c
smpboot.c sched: Fix unreleased llc_shared_mask bit during CPU hotplug 2014-10-05 14:54:14 -07:00
stacktrace.c
step.c
sys_x86_64.c mm: larger stack guard gap, between vmas 2017-07-11 00:00:39 +00:00
syscall_32.c
syscall_64.c
tboot.c
tce_64.c
test_nx.c
test_rodata.c
time.c
tls.c x86, tls: Interpret an all-zero struct user_desc as "no segment" 2015-01-29 17:40:56 -08:00
tls.h
topology.c
trace_clock.c
traps.c x86/asm/traps: Disable tracing and kprobes in fixup_bad_iret and sync_regs 2015-01-29 17:40:56 -08:00
tsc.c x86/platform: Fix Geode LX timekeeping in the generic x86 build 2015-10-22 14:37:49 -07:00
tsc_sync.c
uprobes.c
verify_cpu.S x86/cpu: Call verify_cpu() after having entered long mode too 2015-12-09 13:40:08 -05:00
vm86_32.c
vmlinux.lds.S
vsmp_64.c
vsyscall_64.c x86_64/vsyscall: Fix warn_bad_vsyscall log output 2014-09-05 16:28:36 -07:00
vsyscall_emu_64.S
vsyscall_trace.h
x86_init.c
x8664_ksyms_64.c x86_64: kasan: add interceptors for memset/memmove/memcpy functions 2015-05-04 14:03:56 -07:00
xsave.c x86/fpu: Avoid math_state_restore() without used_math() in __restore_xstate_sig() 2015-03-26 15:01:00 +01:00