]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.18.137/mm-enforce-min-addr-even-if-capable-in-expand_downwards.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.18.137 / mm-enforce-min-addr-even-if-capable-in-expand_downwards.patch
1 From 0a1d52994d440e21def1c2174932410b4f2a98a1 Mon Sep 17 00:00:00 2001
2 From: Jann Horn <jannh@google.com>
3 Date: Wed, 27 Feb 2019 21:29:52 +0100
4 Subject: mm: enforce min addr even if capable() in expand_downwards()
5
6 From: Jann Horn <jannh@google.com>
7
8 commit 0a1d52994d440e21def1c2174932410b4f2a98a1 upstream.
9
10 security_mmap_addr() does a capability check with current_cred(), but
11 we can reach this code from contexts like a VFS write handler where
12 current_cred() must not be used.
13
14 This can be abused on systems without SMAP to make NULL pointer
15 dereferences exploitable again.
16
17 Fixes: 8869477a49c3 ("security: protect from stack expansion into low vm addresses")
18 Cc: stable@kernel.org
19 Signed-off-by: Jann Horn <jannh@google.com>
20 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
21 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
22
23 ---
24 mm/mmap.c | 7 +++----
25 1 file changed, 3 insertions(+), 4 deletions(-)
26
27 --- a/mm/mmap.c
28 +++ b/mm/mmap.c
29 @@ -2292,12 +2292,11 @@ int expand_downwards(struct vm_area_stru
30 {
31 struct vm_area_struct *prev;
32 unsigned long gap_addr;
33 - int error;
34 + int error = 0;
35
36 address &= PAGE_MASK;
37 - error = security_mmap_addr(address);
38 - if (error)
39 - return error;
40 + if (address < mmap_min_addr)
41 + return -EPERM;
42
43 /* Enforce stack_guard_gap */
44 gap_addr = address - stack_guard_gap;