android_kernel_oneplus_msm8998/arch/arm
Hugh Dickins 4b35943067 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.

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>
[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]
Signed-off-by: Willy Tarreau <w@1wt.eu>
[gkh: minor build fixes for 4.4]
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-06-26 07:13:11 +02:00
..
boot ARM: dts: imx6dl: Fix the VDD_ARM_CAP voltage for 396MHz operation 2017-06-17 06:39:35 +02:00
common ARM: sa1111: fix pcmcia suspend/resume 2016-10-07 15:23:44 +02:00
configs ARM: Fix broken USB support in multi_v7_defconfig for sunxi devices 2016-01-07 16:02:19 +01:00
crypto crypto: arm/aes-ce - fix for big endian 2017-01-12 11:22:50 +01:00
firmware
include arm/arm64: KVM: Enforce unconditional flush to PoC when mapping to stage-2 2017-03-12 06:37:28 +01:00
kernel ARM: 8452/3: PJ4: make coprocessor access sequences buildable in Thumb2 mode 2017-05-14 13:32:54 +02:00
kvm KVM: arm/arm64: Handle possible NULL stage2 pud when ageing pages 2017-06-14 13:16:25 +02:00
lib ARM: 8658/1: uaccess: fix zeroing of 64-bit get_user() 2017-02-23 17:43:09 +01:00
mach-alpine
mach-asm9260
mach-at91 ARM: at91: pm: cpu_idle: switch DDR to power-down mode 2017-03-30 09:35:18 +02:00
mach-axxia
mach-bcm ARM: SoC platform updates for v4.4 2015-11-10 14:56:23 -08:00
mach-berlin arm: berlin: add CPU hotplug support 2015-10-15 21:14:28 +02:00
mach-clps711x
mach-cns3xxx CNS3xxx: Fix PCI cns3xxx_write_config() 2016-05-11 11:21:11 +02:00
mach-davinci ARM: davinci: da850: don't add emac clock to lookup table twice 2017-01-12 11:22:43 +01:00
mach-digicolor ARM: digicolor: select pinctrl/gpio driver 2015-10-15 22:27:30 +02:00
mach-dove ARM: dove: Fix legacy get_irqnr_and_base 2015-11-25 14:59:12 +00:00
mach-ebsa110
mach-efm32
mach-ep93xx
mach-exynos ARM: EXYNOS: Properly skip unitialized parent clock in power domain on 2016-05-11 11:21:14 +02:00
mach-footbridge genirq: Remove irq argument from irq flow handlers 2015-09-16 15:47:51 +02:00
mach-gemini ARM: gemini: remove unnecessary mdio-gpio includes 2015-10-21 19:50:43 -07:00
mach-highbank
mach-hisi
mach-imx ARM: imx6: add missing BM_CLPCR_BYPASS_PMIC_READY setting for imx6sx 2016-09-24 10:07:39 +02:00
mach-integrator
mach-iop13xx genirq: Remove irq argument from irq flow handlers 2015-09-16 15:47:51 +02:00
mach-iop32x
mach-iop33x
mach-ixp4xx ARM: ixp4xx: fix read{b,w,l} return types 2015-12-01 23:45:30 +01:00
mach-keystone ARM: keystone: Update compatible to have SoC specific matches 2015-10-06 09:51:08 -07:00
mach-ks8695
mach-lpc18xx
mach-lpc32xx genirq: Remove irq argument from irq flow handlers 2015-09-16 15:47:51 +02:00
mach-mediatek ARM: SoC platform updates for v4.4 2015-11-10 14:56:23 -08:00
mach-meson ARM: meson: Enable Meson8b SoCs 2015-10-08 17:22:11 +02:00
mach-mmp
mach-moxart
mach-mv78xx0
mach-mvebu ARM: mvebu: fix HW I/O coherency related deadlocks 2016-07-27 09:47:39 -07:00
mach-mxs
mach-netx genirq: Remove irq argument from irq flow handlers 2015-09-16 15:47:51 +02:00
mach-nomadik
mach-nspire
mach-omap1 ARM: OMAP1: Remove board support for VoiceBlue board 2015-10-12 10:36:55 -07:00
mach-omap2 ARM: OMAP5 / DRA7: Fix HYP mode boot for thumb2 build 2017-05-14 13:32:55 +02:00
mach-orion5x ARM: orion5x: Fix legacy get_irqnr_and_base 2015-11-25 15:01:00 +00:00
mach-picoxcell
mach-prima2 ARM: prima2: always enable reset controller 2016-05-04 14:48:53 -07:00
mach-pxa ARM: pxa: pxa_cplds: fix interrupt handling 2016-10-31 04:14:01 -06:00
mach-qcom ARM: Remove __ref on hotplug cpu die path 2015-10-22 09:55:03 -07:00
mach-realview net: smc91x: fix SMC accesses 2016-09-30 10:18:37 +02:00
mach-rockchip clocksource: cosmetic: Drop OF 'dependency' from symbols 2015-10-01 02:18:39 +02:00
mach-rpc genirq: Remove irq argument from irq flow handlers 2015-09-16 15:47:51 +02:00
mach-s3c24xx cpufreq: s3c24xx: Do not mark s3c2410_plls_add as __init 2015-11-27 10:10:32 +09:00
mach-s3c64xx ASoC: samsung: pass DMA channels as pointers 2016-04-12 09:08:32 -07:00
mach-s5pv210
mach-sa1100 ARM: sa1100: clear reset status prior to reboot 2016-10-07 15:23:43 +02:00
mach-shmobile ARM: shmobile: fix regulator quirk for Gen2 2016-10-07 15:23:43 +02:00
mach-socfpga ARM: SoCFPGA: Fix secondary CPU startup in thumb2 kernel 2016-05-11 11:21:14 +02:00
mach-spear ARM: SoC cleanups for v4.4 2015-11-10 14:48:36 -08:00
mach-sti
mach-stm32
mach-sunxi ARM: SoC platform updates for v4.4 2015-11-10 14:56:23 -08:00
mach-tegra ARM: SoC platform updates for v4.4 2015-11-10 14:56:23 -08:00
mach-u300 spi: Updates for v4.4 2015-11-05 13:15:12 -08:00
mach-uniphier ARM: uniphier: rework SMP operations to use trampoline code 2015-10-27 09:20:53 +09:00
mach-ux500 ARM: ux500: fix prcmu_is_cpu_in_wfi() calculation 2017-01-26 08:23:49 +01:00
mach-versatile
mach-vexpress ARM: Remove __ref on hotplug cpu die path 2015-10-22 09:55:03 -07:00
mach-vt8500
mach-w90x900
mach-zx ARM: zx: only build power domain code when CONFIG_PM=y 2015-11-19 16:16:45 +01:00
mach-zynq ARM: zynq: Reserve correct amount of non-DMA RAM 2017-01-15 13:41:36 +01:00
mm mm: larger stack guard gap, between vmas 2017-06-26 07:13:11 +02:00
net ARM: net: bpf: fix zero right shift 2016-01-06 01:32:09 -05:00
nwfpe
oprofile
plat-iop
plat-omap
plat-orion mvebu fixes for 4.3 (part 1) 2015-10-14 17:10:55 +02:00
plat-pxa ARM: pxa: ssp: Fix build error by removing originally incorrect DT binding 2015-09-13 12:55:27 +02:00
plat-samsung ASoC: samsung: pass DMA channels as pointers 2016-04-12 09:08:32 -07:00
plat-versatile
probes
tools
vdso ARM: 8449/1: fix bug in vdsomunge swab32 macro 2015-10-29 15:20:15 +00:00
vfp
xen arm/xen: Use alloc_percpu rather than __alloc_percpu 2017-01-06 11:16:17 +01:00
Kconfig ARM: 8454/1: OF implies OF_FLATTREE 2015-11-28 23:26:12 +00:00
Kconfig-nommu
Kconfig.debug ARM: debug-ll: fix BCM63xx entry for multiplatform 2016-03-03 15:07:08 -08:00
Makefile