android_kernel_sony_msm8994/Documentation
Hugh Dickins 6c8f4fb778
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-09-16 23:08:21 +02:00
..
ABI 32.3.A.0.372 2017-01-31 13:56:35 +01:00
accounting
acpi Merge branch 'for-linus' of git://git.infradead.org/users/vkoul/slave-dma 2013-05-09 09:46:45 -07:00
aoe
arm msm: broadcast: Remove unused TSC and TSPP2 drivers 2016-07-21 03:08:47 -07:00
arm64 arm64: add early_ioremap support 2014-08-15 11:45:24 -07:00
ata ata: ahci: MSM AHCI controller driver 2013-09-04 16:25:35 -07:00
auxdisplay
backlight
blackfin
block Documentation: block: ROW I/O scheduler 2013-07-08 05:54:58 -07:00
blockdev UPSTREAM: zram: deprecate zram attrs sysfs nodes 2016-05-10 13:15:36 +05:30
bus-devices
cdrom
cgroups cgroup: Add generic cgroup subsystem permission checks 2013-07-01 13:38:49 -07:00
connector
console
cpu-freq cpufreq: Implement light weight ->target_index() routine 2013-12-20 19:07:16 -08:00
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-10 13:15:52 +05:30
devicetree Merge remote-tracking branch 'caf/LA.BF64.1.2.3_rb1.11' into HEAD 2017-04-17 14:23:09 +02:00
DocBook Documentation: fix DOCBOOKS=... building 2014-06-11 12:03:22 -07:00
driver-model devres: Add devm_get_free_pages API 2014-07-31 15:26:44 -07:00
dvb media: dvb: mpq: Use kthread instead of workqueue 2013-09-04 15:39:41 -07:00
early-userspace
EDID
extcon
fault-injection
fb
filesystems BACKPORT: mm: /proc/pid/smaps:: show proportional swap share of the mapping 2016-05-10 13:15:39 +05:30
firmware_class
frv
hid
hwmon hwmon: (k10temp) Add support for Fam16h (Kabini) 2013-09-07 22:09:59 -07:00
i2c i2c: i801: enable Intel BayTrail SMBUS 2014-06-07 13:25:35 -07:00
i2o
ia64
ide
infiniband
input Merge "input: add new input event code to pass timestamp to userspace" 2014-09-20 07:33:59 -07:00
ioctl
isdn
ja_JP Documentation: Update stable address in Chinese and Japanese translations 2014-06-07 13:25:35 -07:00
kbuild
kdump
ko_KR
laptops
leds
m68k block: remove refs to XD disks from documentation 2013-05-17 15:17:12 +02:00
make
memory-devices
metag
mips
misc-devices
mmc mmc: use percentage changed sectors as indication to check BKOPS need 2013-09-04 15:47:27 -07:00
mn10300
mtd mtd: msm_qpic_nand: Initial driver for QPIC based NAND controller 2013-09-04 15:04:24 -07:00
namespaces
netlabel
networking ipv6: sysctl to restrict candidate source addresses 2016-05-10 13:14:57 +05:30
nfc
parisc parisc: document the shadow registers 2013-07-21 18:21:26 -07:00
PCI PCI/checkpatch: Deprecate DEFINE_PCI_DEVICE_TABLE 2014-10-10 15:45:26 -07:00
pcmcia
power power: add POWER_SUPPLY_PROP_RESISTANCE_ID property 2014-07-28 10:42:40 -07:00
powerpc powerpc/tm: Fix userspace stack corruption on signal delivery for active transactions 2013-06-01 08:29:23 +10:00
pps
prctl
pti
ptp
rapidio rapidio: documentation update for enumeration changes 2013-05-24 16:22:50 -07:00
RCU
s390
scheduler Revert "sched: Use only partial wait time as task demand" 2015-05-20 12:39:34 -07:00
scsi
security
serial
sh
sound ALSA: compress: Add support to send codec specific data 2015-09-03 11:55:45 -07:00
spi
sysctl pipe: limit the per-user amount of pages allocated in pipes 2017-09-13 17:36:00 +02:00
target
thermal
timers time: Remove CONFIG_TIMER_STATS 2017-09-02 18:04:10 +02:00
trace trace: cpufreq: Add tracing for min/max cpufreq 2016-05-10 13:15:17 +05:30
usb USB: ice40-hcd: Add ICE40 FPGA based SPI to Inter-Chip USB host driver 2014-03-10 11:18:35 +05:30
vDSO
video4linux media: media: gspca: sn9c20x: add ID for Genius Look 1320 V2 2014-05-06 07:55:31 -07:00
virtual
vm UPSTREAM: zsmalloc: zsmalloc documentation 2016-05-10 13:15:34 +05:30
w1
watchdog
wimax
x86 x86-64, espfix: Don't leak bits 31:16 of %esp returning to 16-bit stack 2014-08-07 14:30:26 -07:00
xtensa xtensa: document MMUv3 setup sequence 2013-05-09 01:07:09 -07:00
zh_CN Documentation: Update stable address in Chinese and Japanese translations 2014-06-07 13:25:35 -07:00
.gitignore
00-INDEX Documentation: Add documentation for the MIPI-BIF framework 2013-09-04 16:14:56 -07:00
android.txt cpufreq: remove CONFIG_CPU_FREQ_TABLE 2013-12-20 19:07:16 -08:00
applying-patches.txt
atomic_ops.txt
bad_memory.txt
basic_profiling.txt
bcache.txt bcache: clarify free/available/unused space 2013-05-15 00:42:52 -07:00
bif-framework.txt bif: bif-core: add BIF NVM object writing support 2013-10-10 13:29:46 -07:00
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
cpu-hotplug.txt Doc/cpu-hotplug: Specify race-free way to register CPU hotplug callbacks 2014-07-01 13:44:57 -07:00
cpu-load.txt
cputopology.txt
crc32.txt
dcdbas.txt
debugging-modules.txt
debugging-via-ohci1394.txt
dell_rbu.txt
devices.txt block: remove refs to XD disks from documentation 2013-05-17 15:17:12 +02:00
digsig.txt
DMA-API-HOWTO.txt
DMA-API.txt
DMA-attributes.txt common: DMA-mapping: Add strongly ordered memory attribute 2013-07-08 05:54:54 -07:00
dma-buf-sharing.txt
DMA-ISA-LPC.txt
dmaengine.txt
dmatest.txt dmatest: do not allow to interrupt ongoing tests 2013-06-08 02:13:44 +05:30
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
HOWTO
hw_random.txt
hwspinlock.txt
init.txt
initrd.txt
intel_txt.txt
Intel-IOMMU.txt
io_ordering.txt
io-mapping.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-09-16 23:08:21 +02:00
kernel-per-CPU-kthreads.txt
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
lzo.txt Documentation: lzo: document part of the encoding 2014-10-30 09:35:11 -07:00
magic-number.txt
Makefile
ManagementStyle
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 debugging: keep track of page owners 2014-03-28 13:33:08 -07:00
parport-lowlevel.txt
parport.txt
percpu-rw-semaphore.txt
phy.txt phy: core: Let node ptr of PHY point to PHY and not of PHY provider 2014-09-18 14:55:47 +03:00
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
SAK.txt
SecurityBugs
serial-console.txt
sgi-ioc4.txt
sgi-visws.txt
SM501.txt
smsc_ece1099.txt
sparse.txt
spinlocks.txt
stable_api_nonsense.txt
stable_kernel_rules.txt stable_kernel_rules: Add pointer to netdev-FAQ for network patches 2014-09-05 16:28:33 -07:00
static-keys.txt
SubmitChecklist
SubmittingDrivers
SubmittingPatches Documentation/SubmittingPatches: describe the Fixes: tag 2014-07-06 18:54:15 -07:00
svga.txt
sync.txt sync: add Documentation/sync.txt 2013-07-01 14:16:12 -07:00
sysfs-rules.txt
sysrq.txt
this_cpu_ops.txt
unaligned-memory-access.txt
unicode.txt
unshare.txt
vfio.txt
VGA-softcursor.txt
vgaarbiter.txt
video-output.txt
vme_api.txt
volatile-considered-harmful.txt
workqueue.txt
xz.txt
zorro.txt