]>
Commit | Line | Data |
---|---|---|
e843e42a GKH |
1 | From 5ad356eabc47d26a92140a0c4b20eba471c10de3 Mon Sep 17 00:00:00 2001 |
2 | From: Greg Hackmann <ghackmann@android.com> | |
3 | Date: Wed, 15 Aug 2018 12:51:21 -0700 | |
4 | Subject: arm64: mm: check for upper PAGE_SHIFT bits in pfn_valid() | |
5 | ||
6 | From: Greg Hackmann <ghackmann@android.com> | |
7 | ||
8 | commit 5ad356eabc47d26a92140a0c4b20eba471c10de3 upstream. | |
9 | ||
10 | ARM64's pfn_valid() shifts away the upper PAGE_SHIFT bits of the input | |
11 | before seeing if the PFN is valid. This leads to false positives when | |
12 | some of the upper bits are set, but the lower bits match a valid PFN. | |
13 | ||
14 | For example, the following userspace code looks up a bogus entry in | |
15 | /proc/kpageflags: | |
16 | ||
17 | int pagemap = open("/proc/self/pagemap", O_RDONLY); | |
18 | int pageflags = open("/proc/kpageflags", O_RDONLY); | |
19 | uint64_t pfn, val; | |
20 | ||
21 | lseek64(pagemap, [...], SEEK_SET); | |
22 | read(pagemap, &pfn, sizeof(pfn)); | |
23 | if (pfn & (1UL << 63)) { /* valid PFN */ | |
24 | pfn &= ((1UL << 55) - 1); /* clear flag bits */ | |
25 | pfn |= (1UL << 55); | |
26 | lseek64(pageflags, pfn * sizeof(uint64_t), SEEK_SET); | |
27 | read(pageflags, &val, sizeof(val)); | |
28 | } | |
29 | ||
30 | On ARM64 this causes the userspace process to crash with SIGSEGV rather | |
31 | than reading (1 << KPF_NOPAGE). kpageflags_read() treats the offset as | |
32 | valid, and stable_page_flags() will try to access an address between the | |
33 | user and kernel address ranges. | |
34 | ||
35 | Fixes: c1cc1552616d ("arm64: MMU initialisation") | |
36 | Cc: stable@vger.kernel.org | |
37 | Signed-off-by: Greg Hackmann <ghackmann@google.com> | |
38 | Signed-off-by: Will Deacon <will.deacon@arm.com> | |
39 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
40 | ||
41 | --- | |
42 | arch/arm64/mm/init.c | 6 +++++- | |
43 | 1 file changed, 5 insertions(+), 1 deletion(-) | |
44 | ||
45 | --- a/arch/arm64/mm/init.c | |
46 | +++ b/arch/arm64/mm/init.c | |
47 | @@ -120,7 +120,11 @@ static void __init zone_sizes_init(unsig | |
48 | #ifdef CONFIG_HAVE_ARCH_PFN_VALID | |
49 | int pfn_valid(unsigned long pfn) | |
50 | { | |
51 | - return memblock_is_memory(pfn << PAGE_SHIFT); | |
52 | + phys_addr_t addr = pfn << PAGE_SHIFT; | |
53 | + | |
54 | + if ((addr >> PAGE_SHIFT) != pfn) | |
55 | + return 0; | |
56 | + return memblock_is_memory(addr); | |
57 | } | |
58 | EXPORT_SYMBOL(pfn_valid); | |
59 | #endif |