android_kernel_samsung_msm8976/Documentation
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
..
ABI Merge remote-tracking branch 'f2fs/linux-3.10.y' into HEAD 2017-04-18 17:02:28 +02:00
DocBook cfg80211: Add option to report the bss entry in connect result 2016-09-07 16:07:24 +05:30
EDID
PCI
RCU rcu: Add GP-kthread-starvation checks to CPU stall warnings 2015-04-01 12:35:22 -07:00
accounting
acpi
aoe
arm msm: broadcast: Remove unused TSC and TSPP2 drivers 2015-10-07 07:29:13 -07:00
arm64
ata
auxdisplay
backlight
blackfin
block
blockdev UPSTREAM: zram: deprecate zram attrs sysfs nodes 2016-05-18 14:35:54 +05:30
bus-devices
cdrom
cgroups
connector
console
cpu-freq
cpuidle
cris
crypto crypto: qcom: Add support for Inline Crypto Engine 2014-12-05 09:37:20 -08:00
development-process
device-mapper CHROMIUM: dm: boot time specification of dm= 2016-05-18 14:36:11 +05:30
devicetree Merge remote-tracking branch 'f2fs/linux-3.10.y' into HEAD 2017-04-18 17:02:28 +02:00
driver-model
dvb
early-userspace
extcon
fault-injection
fb
filesystems This is the 3.10.101 stable release 2017-04-18 17:17:55 +02:00
firmware_class
frv
hid
hwmon
i2c
i2o
ia64
ide
infiniband
input
ioctl
isdn
ja_JP
kbuild
kdump
ko_KR
laptops
leds
m68k
make
memory-devices
metag
mips
misc-devices
mmc
mn10300
mtd
namespaces
netlabel
networking net: ipv6: Add a sysctl to make optimistic addresses useful candidates 2016-06-10 17:22:49 -07:00
nfc
parisc
pcmcia
power
powerpc
pps
prctl
pti
ptp
rapidio
s390
scheduler Revert "sched: Use only partial wait time as task demand" 2015-07-15 10:14:09 +05:30
scsi
security
serial
sh
sound ALSA: compress: Add support to send codec specific data 2015-08-10 08:55:22 +05:30
spi
sysctl Import latest Samsung release 2017-04-18 03:43:52 +02:00
target
thermal
timers time: Remove CONFIG_TIMER_STATS 2017-04-22 23:02:59 +02:00
trace trace: cpufreq: Add tracing for min/max cpufreq 2016-05-18 14:34:41 +05:30
usb
vDSO
video4linux
virtual
vm UPSTREAM: zsmalloc: zsmalloc documentation 2016-05-18 14:35:53 +05:30
w1
watchdog
wimax
x86 x86_64: add KASan support 2015-05-04 14:03:57 -07:00
xtensa
zh_CN
.gitignore
00-INDEX
BUG-HUNTING
Changes
CodingStyle
DMA-API-HOWTO.txt
DMA-API.txt
DMA-ISA-LPC.txt
DMA-attributes.txt
HOWTO
IPMI.txt
IRQ-affinity.txt
IRQ-domain.txt
IRQ.txt
Intel-IOMMU.txt
Makefile
ManagementStyle
SAK.txt
SM501.txt
SecurityBugs
SubmitChecklist
SubmittingDrivers
SubmittingPatches
VGA-softcursor.txt
android.txt
applying-patches.txt
atomic_ops.txt
bad_memory.txt
basic_profiling.txt
bcache.txt
bif-framework.txt
binfmt_misc.txt
braille-console.txt
bt8xxgpio.txt
btmrvl.txt
bus-virt-phys-mapping.txt
cachetlb.txt
circular-buffers.txt
clk.txt
coccinelle.txt
cpu-hotplug.txt
cpu-load.txt
cputopology.txt
crc32.txt
dcdbas.txt
debugging-modules.txt
debugging-via-ohci1394.txt
dell_rbu.txt
devices.txt
digsig.txt
dma-buf-sharing.txt
dmaengine.txt
dmatest.txt
dontdiff
dynamic-debug-howto.txt
edac.txt
eisa.txt
email-clients.txt
flexible-arrays.txt
futex-requeue-pi.txt
gcov.txt
gpio.txt
highuid.txt
hw_random.txt
hwspinlock.txt
init.txt
initrd.txt
intel_txt.txt
io-mapping.txt
io_ordering.txt
iostats.txt
irqflags-tracing.txt
isapnp.txt
java.txt
kasan.txt kasan: enable instrumentation of global variables 2015-05-04 14:03:57 -07:00
kernel-doc-nano-HOWTO.txt
kernel-docs.txt
kernel-parameters.txt mm: larger stack guard gap, between vmas 2017-07-11 00:00:39 +00:00
kernel-per-CPU-kthreads.txt
kmemcheck.txt
kmemleak.txt kmemleak: allow freeing internal objects after kmemleak was disabled 2015-03-11 16:14:44 +05:30
kobject.txt
kprobes.txt
kref.txt
ldm.txt
local_ops.txt
lockdep-design.txt
lockstat.txt
lockup-watchdogs.txt
logo.gif
logo.txt
lzo.txt
magic-number.txt
md.txt
media-framework.txt
memory-barriers.txt
memory-hotplug.txt
mono.txt
mutex-design.txt
nommu-mmap.txt
numastat.txt
oops-tracing.txt
padata.txt
page_owner.c
parport-lowlevel.txt
parport.txt
percpu-rw-semaphore.txt
phy.txt
pi-futex.txt
pinctrl.txt
pnp.txt
preempt-locking.txt
printk-formats.txt
pwm.txt
ramoops.txt pstore-ram: Allow optional mapping with pgprot_noncached 2015-01-16 06:59:00 -08:00
rbtree.txt
remoteproc.txt
rfkill.txt
robust-futex-ABI.txt
robust-futexes.txt
rpmsg.txt
rt-mutex-design.txt
rt-mutex.txt
rtc.txt
serial-console.txt
sgi-ioc4.txt
sgi-visws.txt
smsc_ece1099.txt
sparse.txt
spinlocks.txt
stable_api_nonsense.txt
stable_kernel_rules.txt
static-keys.txt
svga.txt
sync.txt
sysfs-rules.txt
sysrq.txt
this_cpu_ops.txt
unaligned-memory-access.txt
unicode.txt
unshare.txt
vfio.txt
vgaarbiter.txt
video-output.txt
vme_api.txt
volatile-considered-harmful.txt
workqueue.txt
xz.txt
zorro.txt