|
19 | 19 | #include <linux/sched.h>
|
20 | 20 | #include <linux/seq_file.h>
|
21 | 21 | #include <linux/highmem.h>
|
| 22 | +#include <linux/pci.h> |
22 | 23 |
|
| 24 | +#include <asm/e820/types.h> |
23 | 25 | #include <asm/pgtable.h>
|
24 | 26 |
|
25 | 27 | /*
|
@@ -241,6 +243,29 @@ static unsigned long normalize_addr(unsigned long u)
|
241 | 243 | return (signed long)(u << shift) >> shift;
|
242 | 244 | }
|
243 | 245 |
|
| 246 | +static void note_wx(struct pg_state *st) |
| 247 | +{ |
| 248 | + unsigned long npages; |
| 249 | + |
| 250 | + npages = (st->current_address - st->start_address) / PAGE_SIZE; |
| 251 | + |
| 252 | +#ifdef CONFIG_PCI_BIOS |
| 253 | + /* |
| 254 | + * If PCI BIOS is enabled, the PCI BIOS area is forced to WX. |
| 255 | + * Inform about it, but avoid the warning. |
| 256 | + */ |
| 257 | + if (pcibios_enabled && st->start_address >= PAGE_OFFSET + BIOS_BEGIN && |
| 258 | + st->current_address <= PAGE_OFFSET + BIOS_END) { |
| 259 | + pr_warn_once("x86/mm: PCI BIOS W+X mapping %lu pages\n", npages); |
| 260 | + return; |
| 261 | + } |
| 262 | +#endif |
| 263 | + /* Account the WX pages */ |
| 264 | + st->wx_pages += npages; |
| 265 | + WARN_ONCE(1, "x86/mm: Found insecure W+X mapping at address %pS\n", |
| 266 | + (void *)st->start_address); |
| 267 | +} |
| 268 | + |
244 | 269 | /*
|
245 | 270 | * This function gets called on a break in a continuous series
|
246 | 271 | * of PTE entries; the next one is different so we need to
|
@@ -276,14 +301,8 @@ static void note_page(struct seq_file *m, struct pg_state *st,
|
276 | 301 | unsigned long delta;
|
277 | 302 | int width = sizeof(unsigned long) * 2;
|
278 | 303 |
|
279 |
| - if (st->check_wx && (eff & _PAGE_RW) && !(eff & _PAGE_NX)) { |
280 |
| - WARN_ONCE(1, |
281 |
| - "x86/mm: Found insecure W+X mapping at address %p/%pS\n", |
282 |
| - (void *)st->start_address, |
283 |
| - (void *)st->start_address); |
284 |
| - st->wx_pages += (st->current_address - |
285 |
| - st->start_address) / PAGE_SIZE; |
286 |
| - } |
| 304 | + if (st->check_wx && (eff & _PAGE_RW) && !(eff & _PAGE_NX)) |
| 305 | + note_wx(st); |
287 | 306 |
|
288 | 307 | /*
|
289 | 308 | * Now print the actual finished series
|
|
0 commit comments