]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
21b127cececfc75ce454b97298b80653902499d7
[thirdparty/kernel/stable-queue.git] /
1 From fc5f9d5f151c9fff21d3d1d2907b888a5aec3ff7 Mon Sep 17 00:00:00 2001
2 From: Baoquan He <bhe@redhat.com>
3 Date: Thu, 4 May 2017 10:25:47 +0800
4 Subject: x86/mm: Fix boot crash caused by incorrect loop count calculation in sync_global_pgds()
5
6 From: Baoquan He <bhe@redhat.com>
7
8 commit fc5f9d5f151c9fff21d3d1d2907b888a5aec3ff7 upstream.
9
10 Jeff Moyer reported that on his system with two memory regions 0~64G and
11 1T~1T+192G, and kernel option "memmap=192G!1024G" added, enabling KASLR
12 will make the system hang intermittently during boot. While adding 'nokaslr'
13 won't.
14
15 The back trace is:
16
17 Oops: 0000 [#1] SMP
18
19 RIP: memcpy_erms()
20 [ .... ]
21 Call Trace:
22 pmem_rw_page()
23 bdev_read_page()
24 do_mpage_readpage()
25 mpage_readpages()
26 blkdev_readpages()
27 __do_page_cache_readahead()
28 force_page_cache_readahead()
29 page_cache_sync_readahead()
30 generic_file_read_iter()
31 blkdev_read_iter()
32 __vfs_read()
33 vfs_read()
34 SyS_read()
35 entry_SYSCALL_64_fastpath()
36
37 This crash happens because the for loop count calculation in sync_global_pgds()
38 is not correct. When a mapping area crosses PGD entries, we should
39 calculate the starting address of region which next PGD covers and assign
40 it to next for loop count, but not add PGDIR_SIZE directly. The old
41 code works right only if the mapping area is an exact multiple of PGDIR_SIZE,
42 otherwize the end region could be skipped so that it can't be synchronized
43 to all other processes from kernel PGD init_mm.pgd.
44
45 In Jeff's system, emulated pmem area [1024G, 1216G) is smaller than
46 PGDIR_SIZE. While 'nokaslr' works because PAGE_OFFSET is 1T aligned, it
47 makes this area be mapped inside one PGD entry. With KASLR enabled,
48 this area could cross two PGD entries, then the next PGD entry won't
49 be synced to all other processes. That is why we saw empty PGD.
50
51 Fix it.
52
53 Reported-by: Jeff Moyer <jmoyer@redhat.com>
54 Signed-off-by: Baoquan He <bhe@redhat.com>
55 Cc: Andrew Morton <akpm@linux-foundation.org>
56 Cc: Andy Lutomirski <luto@kernel.org>
57 Cc: Borislav Petkov <bp@alien8.de>
58 Cc: Brian Gerst <brgerst@gmail.com>
59 Cc: Dan Williams <dan.j.williams@intel.com>
60 Cc: Dave Hansen <dave.hansen@linux.intel.com>
61 Cc: Dave Young <dyoung@redhat.com>
62 Cc: Denys Vlasenko <dvlasenk@redhat.com>
63 Cc: H. Peter Anvin <hpa@zytor.com>
64 Cc: Jinbum Park <jinb.park7@gmail.com>
65 Cc: Josh Poimboeuf <jpoimboe@redhat.com>
66 Cc: Kees Cook <keescook@chromium.org>
67 Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
68 Cc: Linus Torvalds <torvalds@linux-foundation.org>
69 Cc: Peter Zijlstra <peterz@infradead.org>
70 Cc: Thomas Garnier <thgarnie@google.com>
71 Cc: Thomas Gleixner <tglx@linutronix.de>
72 Cc: Yasuaki Ishimatsu <yasu.isimatu@gmail.com>
73 Cc: Yinghai Lu <yinghai@kernel.org>
74 Link: http://lkml.kernel.org/r/1493864747-8506-1-git-send-email-bhe@redhat.com
75 Signed-off-by: Ingo Molnar <mingo@kernel.org>
76 Signed-off-by: Dan Williams <dan.j.williams@intel.com>
77 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
78 ---
79 arch/x86/mm/init_64.c | 8 ++++----
80 1 file changed, 4 insertions(+), 4 deletions(-)
81
82 --- a/arch/x86/mm/init_64.c
83 +++ b/arch/x86/mm/init_64.c
84 @@ -94,10 +94,10 @@ __setup("noexec32=", nonx32_setup);
85 */
86 void sync_global_pgds(unsigned long start, unsigned long end, int removed)
87 {
88 - unsigned long address;
89 + unsigned long addr;
90
91 - for (address = start; address <= end; address += PGDIR_SIZE) {
92 - const pgd_t *pgd_ref = pgd_offset_k(address);
93 + for (addr = start; addr <= end; addr = ALIGN(addr + 1, PGDIR_SIZE)) {
94 + const pgd_t *pgd_ref = pgd_offset_k(addr);
95 struct page *page;
96
97 /*
98 @@ -113,7 +113,7 @@ void sync_global_pgds(unsigned long star
99 pgd_t *pgd;
100 spinlock_t *pgt_lock;
101
102 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
103 + pgd = (pgd_t *)page_address(page) + pgd_index(addr);
104 /* the pgt_lock only for Xen */
105 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
106 spin_lock(pgt_lock);