android_kernel_google_msm/Documentation
Hugh Dickins 45c60e5957 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: I611023b0bfe1cab7b3e5da13e331a7baaaaf6eb0
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>
Signed-off-by: Flex1911 <dedsa2002@gmail.com>
2017-07-02 13:03:27 +03:00
..
ABI f2fs: introduce lifetime write IO statistics 2016-10-29 23:12:29 +08:00
accounting
acpi Update documentation for parameter *notrigger* in einj.txt 2012-03-30 03:30:19 -04:00
aoe Documentation: remove references to /etc/modprobe.conf 2012-03-30 16:03:15 -07:00
arm uio: msm_sharedmem: Add new device driver for sharedmemory access 2014-07-15 23:59:19 +00:00
auxdisplay
backlight backlight: new backlight driver for LP855x devices 2012-03-23 16:58:33 -07:00
blackfin
block block: Add test-iosched scheduler 2013-02-27 18:13:18 -08:00
blockdev Documentation: remove references to /etc/modprobe.conf 2012-03-30 16:03:15 -07:00
cdrom
cgroups Merge commit 'v3.4-rc3' into android-3.4 2012-04-19 14:42:22 -07:00
connector
console
cpu-freq cpufreq: interactive: add boost pulse interface 2012-05-03 17:41:51 -07:00
cpuidle cpuidle: add a sysfs entry to disable specific C state for debug purpose. 2012-03-30 01:52:58 -04:00
cris
crypto crypto: Add MSM crypto drivers 2013-02-25 11:29:28 -08:00
development-process
device-mapper dm: add verity target 2012-03-28 18:43:38 +01:00
devicetree uio: msm_sharedmem: Add new device driver for sharedmemory access 2014-07-15 23:59:19 +00:00
DocBook ALSA: Remove transfer_ack_{begin,end} callbacks from struct snd_pcm_runtime 2017-03-07 05:44:05 +00:00
driver-model
dvb media: dvb: mpq: Use kthread instead of workqueue 2013-03-07 15:24:04 -08:00
early-userspace
EDID
fault-injection
fb Documentation: remove references to /etc/modprobe.conf 2012-03-30 16:03:15 -07:00
filesystems f2fs: introduce new option for controlling data flush 2016-10-29 23:12:21 +08:00
firmware_class
frv
hid HID: uhid: add documentation 2013-03-04 12:45:09 -08:00
hwmon hwmon: (k10temp) Add support for AMD Trinity CPUs 2012-04-01 10:25:56 -07:00
i2c Documentation: remove references to /etc/modprobe.conf 2012-03-30 16:03:15 -07:00
i2o
ia64
ide Documentation: remove references to /etc/modprobe.conf 2012-03-30 16:03:15 -07:00
infiniband
input Documentation: input.txt: clarify mousedev 'cat' command syntax 2012-03-30 16:03:15 -07:00
ioctl Merge branch 'for-next' of git://gitorious.org/kernel-hsi/kernel-hsi 2012-04-02 09:50:40 -07:00
isdn Documentation: remove references to /etc/modprobe.conf 2012-03-30 16:03:15 -07:00
ja_JP
kbuild Documentation: mention scripts/diffconfig tool 2012-03-30 16:03:15 -07:00
kdump
ko_KR
laptops Documentation: remove references to /etc/modprobe.conf 2012-03-30 16:03:15 -07:00
leds drivers/leds/leds-lp5521.c: support led pattern data 2012-03-23 16:58:34 -07:00
m68k
make
mips
misc-devices
mmc mmc: use percentage changed sectors as indication to check BKOPS need 2013-03-15 17:08:16 -07:00
mn10300
mtd mtd: msm_qpic_nand: Initial driver for QPIC based NAND controller 2013-02-27 18:17:42 -08:00
namespaces
netlabel
networking ipv6: sysctl to restrict candidate source addresses 2015-07-29 13:59:11 +09:00
nfc
parisc
PCI
pcmcia
power Documentation: Point to correct header file 2013-02-25 11:36:56 -08:00
powerpc
pps
prctl Documentation: prctl/seccomp_filter 2014-10-31 19:46:17 -07:00
pti
ptp
rapidio
RCU
s390 Documentation: remove references to /etc/modprobe.conf 2012-03-30 16:03:15 -07:00
scheduler
scsi SCSI updates on 20120331 2012-03-31 13:31:23 -07:00
security KEYS: Add invalidation support 2016-10-29 23:12:12 +08:00
serial Documentation: remove references to /etc/modprobe.conf 2012-03-30 16:03:15 -07:00
sh
sound ALSA: compress: add support for gapless playback 2013-04-18 16:08:45 -07:00
sparc
spi
sysctl FROMLIST: mm: mmap: Add new /proc tunable for mmap_base ASLR. 2016-10-29 23:12:40 +08:00
target
telephony
thermal
timers time: Remove CONFIG_TIMER_STATS 2017-07-02 13:03:26 +03:00
trace Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial 2012-03-20 21:12:50 -07:00
usb usb: misc: Add kickstart bridge driver 2013-02-27 18:19:01 -08:00
vDSO
video4linux Documentation: remove references to /etc/modprobe.conf 2012-03-30 16:03:15 -07:00
virtual Merge branch 'kvm-updates/3.4' of git://git.kernel.org/pub/scm/virt/kvm/kvm 2012-03-28 14:35:31 -07:00
vm ksm: Provide support to use deferred timers for scanner thread 2016-10-29 23:12:17 +08:00
w1
watchdog watchdog: Add support for WDIOC_GETTIMELEFT IOCTL in watchdog core 2012-03-27 20:15:37 +02:00
wimax
x86
zh_CN Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2012-03-20 21:04:47 -07:00
.gitignore
00-INDEX crc32: move long comment about crc32 fundamentals to Documentation/ 2012-03-23 16:58:37 -07:00
android.txt [docs] android: Add android config documentation to boot framework. 2012-04-09 13:53:13 -07:00
applying-patches.txt
atomic_ops.txt
bad_memory.txt
basic_profiling.txt
binfmt_misc.txt
braille-console.txt
bt8xxgpio.txt
btmrvl.txt
BUG-HUNTING
bus-virt-phys-mapping.txt
cachetlb.txt
Changes
circular-buffers.txt
clk.txt
coccinelle.txt
CodingStyle Documentation: CodingStyle: add inline assembly guidelines 2012-03-30 16:03:15 -07:00
cpu-hotplug.txt documentation: remove references to cpu_*_map. 2012-03-29 15:38:31 +10:30
cpu-load.txt
cputopology.txt
crc32.txt crc32: move long comment about crc32 fundamentals to Documentation/ 2012-03-23 16:58:37 -07:00
csdio.txt mmc: Char SDIO Device Driver 2013-02-25 11:29:22 -08:00
dcdbas.txt
debugging-modules.txt
debugging-via-ohci1394.txt
dell_rbu.txt
devices.txt
digsig.txt
DMA-API-HOWTO.txt
DMA-API.txt
DMA-attributes.txt common: DMA-mapping: Add strongly ordered memory attribute 2013-03-07 15:23:21 -08:00
dma-buf-sharing.txt dma-buf: mmap support 2012-05-22 14:01:06 -07:00
DMA-ISA-LPC.txt
dmaengine.txt
dontdiff Documentation: remove 'mach' from dontdiff file 2012-03-30 16:03:15 -07:00
dynamic-debug-howto.txt
edac.txt
eisa.txt
email-clients.txt
feature-removal-schedule.txt Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media 2012-05-14 11:23:37 -07:00
flexible-arrays.txt
futex-requeue-pi.txt
gcov.txt
genlock.txt base: genlock: allow synchronization with a single gralloc handle 2013-02-25 11:29:17 -08:00
gpio.txt
highuid.txt
HOWTO
hw_random.txt
hwspinlock.txt
init.txt
initrd.txt
Intel-IOMMU.txt
intel_txt.txt
io-mapping.txt
io_ordering.txt
iostats.txt
IPMI.txt
IRQ-affinity.txt
IRQ-domain.txt
IRQ.txt
irqflags-tracing.txt
isapnp.txt
java.txt
kernel-doc-nano-HOWTO.txt
kernel-docs.txt
kernel-parameters.txt mm: larger stack guard gap, between vmas 2017-07-02 13:03:27 +03:00
kmemcheck.txt
kmemleak.txt
kobject.txt
kprobes.txt
kref.txt
ldm.txt
local_ops.txt
lockdep-design.txt
lockstat.txt
lockup-watchdogs.txt
logo.gif
logo.txt
magic-number.txt
Makefile mm: move hugepage test examples to tools/testing/selftests/vm 2012-03-28 17:14:37 -07:00
ManagementStyle
mca.txt
md.txt
media-framework.txt
memory-barriers.txt
memory-hotplug.txt
memory.txt
mono.txt Documentation: remove references to /etc/modprobe.conf 2012-03-30 16:03:15 -07:00
mutex-design.txt
nommu-mmap.txt
numastat.txt
oops-tracing.txt
padata.txt
parport-lowlevel.txt
parport.txt Documentation: remove references to /etc/modprobe.conf 2012-03-30 16:03:15 -07:00
pi-futex.txt
pinctrl.txt
pnp.txt
preempt-locking.txt
printk-formats.txt
prio_tree.txt
ramoops.txt
rbtree.txt
remoteproc.txt
rfkill.txt
robust-futex-ABI.txt
robust-futexes.txt
rpmsg.txt
rt-mutex-design.txt
rt-mutex.txt
rtc.txt
SAK.txt
SecurityBugs
serial-console.txt
sgi-ioc4.txt
sgi-visws.txt
SM501.txt
sparse.txt
spinlocks.txt
stable_api_nonsense.txt
stable_kernel_rules.txt
static-keys.txt
SubmitChecklist
SubmittingDrivers
SubmittingPatches
svga.txt
sync.txt sync: add Documentation/sync.txt 2013-03-15 17:13:08 -07:00
sysfs-rules.txt
sysrq.txt Documentation: sysrq: Crutcher Dunnavant is unavailable 2012-03-30 16:03:15 -07:00
unaligned-memory-access.txt
unicode.txt
unshare.txt
VGA-softcursor.txt
vgaarbiter.txt
video-output.txt
volatile-considered-harmful.txt
workqueue.txt
xz.txt
zorro.txt