aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/mm
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2014-04-29 19:46:09 -0400
committerH. Peter Anvin <hpa@linux.intel.com>2014-04-30 17:14:28 -0400
commit3891a04aafd668686239349ea58f3314ea2af86b (patch)
treef1c3b49ceb091a875aaa6e99b6b4a91ea79dc2ec /arch/x86/mm
parentd1db0eea852497762cab43b905b879dfcd3b8987 (diff)
x86-64, espfix: Don't leak bits 31:16 of %esp returning to 16-bit stack
The IRET instruction, when returning to a 16-bit segment, only restores the bottom 16 bits of the user space stack pointer. This causes some 16-bit software to break, but it also leaks kernel state to user space. We have a software workaround for that ("espfix") for the 32-bit kernel, but it relies on a nonzero stack segment base which is not available in 64-bit mode. In checkin: b3b42ac2cbae x86-64, modify_ldt: Ban 16-bit segments on 64-bit kernels we "solved" this by forbidding 16-bit segments on 64-bit kernels, with the logic that 16-bit support is crippled on 64-bit kernels anyway (no V86 support), but it turns out that people are doing stuff like running old Win16 binaries under Wine and expect it to work. This works around this by creating percpu "ministacks", each of which is mapped 2^16 times 64K apart. When we detect that the return SS is on the LDT, we copy the IRET frame to the ministack and use the relevant alias to return to userspace. The ministacks are mapped readonly, so if IRET faults we promote #GP to #DF which is an IST vector and thus has its own stack; we then do the fixup in the #DF handler. (Making #GP an IST exception would make the msr_safe functions unsafe in NMI/MC context, and quite possibly have other effects.) Special thanks to: - Andy Lutomirski, for the suggestion of using very small stack slots and copy (as opposed to map) the IRET frame there, and for the suggestion to mark them readonly and let the fault promote to #DF. - Konrad Wilk for paravirt fixup and testing. - Borislav Petkov for testing help and useful comments. Reported-by: Brian Gerst <brgerst@gmail.com> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com> Link: http://lkml.kernel.org/r/1398816946-3351-1-git-send-email-hpa@linux.intel.com Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Andrew Lutomriski <amluto@gmail.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Dirk Hohndel <dirk@hohndel.org> Cc: Arjan van de Ven <arjan.van.de.ven@intel.com> Cc: comex <comexk@gmail.com> Cc: Alexander van Heukelum <heukelum@fastmail.fm> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: <stable@vger.kernel.org> # consider after upstream merge
Diffstat (limited to 'arch/x86/mm')
-rw-r--r--arch/x86/mm/dump_pagetables.c44
1 files changed, 33 insertions, 11 deletions
diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
index 20621d753d5f..167ffcac16ed 100644
--- a/arch/x86/mm/dump_pagetables.c
+++ b/arch/x86/mm/dump_pagetables.c
@@ -30,12 +30,14 @@ struct pg_state {
30 unsigned long start_address; 30 unsigned long start_address;
31 unsigned long current_address; 31 unsigned long current_address;
32 const struct addr_marker *marker; 32 const struct addr_marker *marker;
33 unsigned long lines;
33 bool to_dmesg; 34 bool to_dmesg;
34}; 35};
35 36
36struct addr_marker { 37struct addr_marker {
37 unsigned long start_address; 38 unsigned long start_address;
38 const char *name; 39 const char *name;
40 unsigned long max_lines;
39}; 41};
40 42
41/* indices for address_markers; keep sync'd w/ address_markers below */ 43/* indices for address_markers; keep sync'd w/ address_markers below */
@@ -46,6 +48,7 @@ enum address_markers_idx {
46 LOW_KERNEL_NR, 48 LOW_KERNEL_NR,
47 VMALLOC_START_NR, 49 VMALLOC_START_NR,
48 VMEMMAP_START_NR, 50 VMEMMAP_START_NR,
51 ESPFIX_START_NR,
49 HIGH_KERNEL_NR, 52 HIGH_KERNEL_NR,
50 MODULES_VADDR_NR, 53 MODULES_VADDR_NR,
51 MODULES_END_NR, 54 MODULES_END_NR,
@@ -68,6 +71,7 @@ static struct addr_marker address_markers[] = {
68 { PAGE_OFFSET, "Low Kernel Mapping" }, 71 { PAGE_OFFSET, "Low Kernel Mapping" },
69 { VMALLOC_START, "vmalloc() Area" }, 72 { VMALLOC_START, "vmalloc() Area" },
70 { VMEMMAP_START, "Vmemmap" }, 73 { VMEMMAP_START, "Vmemmap" },
74 { ESPFIX_BASE_ADDR, "ESPfix Area", 16 },
71 { __START_KERNEL_map, "High Kernel Mapping" }, 75 { __START_KERNEL_map, "High Kernel Mapping" },
72 { MODULES_VADDR, "Modules" }, 76 { MODULES_VADDR, "Modules" },
73 { MODULES_END, "End Modules" }, 77 { MODULES_END, "End Modules" },
@@ -182,7 +186,7 @@ static void note_page(struct seq_file *m, struct pg_state *st,
182 pgprot_t new_prot, int level) 186 pgprot_t new_prot, int level)
183{ 187{
184 pgprotval_t prot, cur; 188 pgprotval_t prot, cur;
185 static const char units[] = "KMGTPE"; 189 static const char units[] = "BKMGTPE";
186 190
187 /* 191 /*
188 * If we have a "break" in the series, we need to flush the state that 192 * If we have a "break" in the series, we need to flush the state that
@@ -197,6 +201,7 @@ static void note_page(struct seq_file *m, struct pg_state *st,
197 st->current_prot = new_prot; 201 st->current_prot = new_prot;
198 st->level = level; 202 st->level = level;
199 st->marker = address_markers; 203 st->marker = address_markers;
204 st->lines = 0;
200 pt_dump_seq_printf(m, st->to_dmesg, "---[ %s ]---\n", 205 pt_dump_seq_printf(m, st->to_dmesg, "---[ %s ]---\n",
201 st->marker->name); 206 st->marker->name);
202 } else if (prot != cur || level != st->level || 207 } else if (prot != cur || level != st->level ||
@@ -208,17 +213,24 @@ static void note_page(struct seq_file *m, struct pg_state *st,
208 /* 213 /*
209 * Now print the actual finished series 214 * Now print the actual finished series
210 */ 215 */
211 pt_dump_seq_printf(m, st->to_dmesg, "0x%0*lx-0x%0*lx ", 216 if (!st->marker->max_lines ||
212 width, st->start_address, 217 st->lines < st->marker->max_lines) {
213 width, st->current_address); 218 pt_dump_seq_printf(m, st->to_dmesg,
214 219 "0x%0*lx-0x%0*lx ",
215 delta = (st->current_address - st->start_address) >> 10; 220 width, st->start_address,
216 while (!(delta & 1023) && unit[1]) { 221 width, st->current_address);
217 delta >>= 10; 222
218 unit++; 223 delta = st->current_address - st->start_address;
224 while (!(delta & 1023) && unit[1]) {
225 delta >>= 10;
226 unit++;
227 }
228 pt_dump_cont_printf(m, st->to_dmesg, "%9lu%c ",
229 delta, *unit);
230 printk_prot(m, st->current_prot, st->level,
231 st->to_dmesg);
219 } 232 }
220 pt_dump_cont_printf(m, st->to_dmesg, "%9lu%c ", delta, *unit); 233 st->lines++;
221 printk_prot(m, st->current_prot, st->level, st->to_dmesg);
222 234
223 /* 235 /*
224 * We print markers for special areas of address space, 236 * We print markers for special areas of address space,
@@ -226,7 +238,17 @@ static void note_page(struct seq_file *m, struct pg_state *st,
226 * This helps in the interpretation. 238 * This helps in the interpretation.
227 */ 239 */
228 if (st->current_address >= st->marker[1].start_address) { 240 if (st->current_address >= st->marker[1].start_address) {
241 if (st->marker->max_lines &&
242 st->lines > st->marker->max_lines) {
243 unsigned long nskip =
244 st->lines - st->marker->max_lines;
245 pt_dump_seq_printf(m, st->to_dmesg,
246 "... %lu entr%s skipped ... \n",
247 nskip,
248 nskip == 1 ? "y" : "ies");
249 }
229 st->marker++; 250 st->marker++;
251 st->lines = 0;
230 pt_dump_seq_printf(m, st->to_dmesg, "---[ %s ]---\n", 252 pt_dump_seq_printf(m, st->to_dmesg, "---[ %s ]---\n",
231 st->marker->name); 253 st->marker->name);
232 } 254 }