linux/arch/arm
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
..
boot ARM: SoC fixes 2017-06-19 16:50:09 +08:00
common ARM: 8675/1: MCPM: ensure not to enter __hyp_soft_restart from loopback and cpu_power_down 2017-05-23 17:26:08 +01:00
configs ARM: configs: add a gemini defconfig 2017-05-18 23:56:47 -07:00
crypto
firmware
include IOMMU Fixes for Linux v4.12-rc4 2017-06-09 22:30:55 -07:00
kernel arm64 2nd set of updates for 4.12: 2017-05-11 11:27:54 -07:00
kvm arm: KVM: Allow unaligned accesses at HYP 2017-06-06 22:20:02 +02:00
lib
mach-alpine
mach-artpec
mach-asm9260
mach-aspeed
mach-at91 Merge tag 'at91-4.12-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux into fixes 2017-06-01 17:07:31 -07:00
mach-axxia
mach-bcm ARM: remove duplicate 'const' annotations' 2017-05-19 10:12:55 +02:00
mach-berlin
mach-clps711x
mach-cns3xxx ARM: remove duplicate 'const' annotations' 2017-05-19 10:12:55 +02:00
mach-davinci ARM: davinci: PM: Do not free useful resources in normal path in 'davinci_pm_init' 2017-05-17 15:25:18 +05:30
mach-digicolor
mach-dove
mach-ebsa110
mach-efm32
mach-ep93xx
mach-exynos
mach-footbridge
mach-gemini
mach-highbank
mach-hisi
mach-imx ARM: SoC driver updates 2017-05-09 10:01:15 -07:00
mach-integrator
mach-iop13xx
mach-iop32x
mach-iop33x
mach-ixp4xx scripts/spelling.txt: add regsiter -> register spelling mistake 2017-05-08 17:15:13 -07:00
mach-keystone
mach-ks8695
mach-lpc18xx
mach-lpc32xx
mach-mediatek
mach-meson
mach-mmp
mach-moxart
mach-mv78xx0
mach-mvebu
mach-mxs
mach-netx
mach-nomadik
mach-nspire
mach-omap1
mach-omap2 ARM: remove duplicate 'const' annotations' 2017-05-19 10:12:55 +02:00
mach-orion5x
mach-oxnas
mach-picoxcell
mach-prima2
mach-pxa
mach-qcom
mach-realview
mach-rockchip
mach-rpc
mach-s3c24xx
mach-s3c64xx regulator: arizona-ldo1: Move pdata into a separate structure 2017-04-25 16:36:32 +01:00
mach-s5pv210
mach-sa1100
mach-shmobile
mach-socfpga
mach-spear ARM: remove duplicate 'const' annotations' 2017-05-19 10:12:55 +02:00
mach-sti
mach-stm32
mach-sunxi
mach-tango
mach-tegra
mach-u300
mach-uniphier
mach-ux500
mach-versatile
mach-vexpress
mach-vt8500
mach-w90x900
mach-zx
mach-zynq
mm mm: larger stack guard gap, between vmas 2017-06-19 21:50:20 +08:00
net arm: use set_memory.h header 2017-05-08 17:15:13 -07:00
nwfpe
oprofile
plat-iop
plat-omap
plat-orion
plat-pxa
plat-samsung
plat-versatile
probes
tools
vdso
vfp
xen xen: Implement EFI reset_system callback 2017-05-02 12:06:50 +02:00
Kconfig ARM: SoC platform updates 2017-05-09 09:49:36 -07:00
Kconfig-nommu
Kconfig.debug
Makefile