Skip to content

Commit c200dac

Browse files
committed
x86/mm: Do not warn about PCI BIOS W+X mappings
PCI BIOS requires the BIOS area 0x0A0000-0x0FFFFFF to be mapped W+X for various legacy reasons. When CONFIG_DEBUG_WX is enabled, this triggers the WX warning, but this is misleading because the mapping is required and is not a result of an accidental oversight. Prevent the full warning when PCI BIOS is enabled and the detected WX mapping is in the BIOS area. Just emit a pr_warn() which denotes the fact. This is partially duplicating the info which the PCI BIOS code emits when it maps the area as executable, but that info is not in the context of the WX checking output. Remove the extra %p printout in the WARN_ONCE() while at it. %pS is enough. Reported-by: Paul Menzel <pmenzel@molgen.mpg.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Borislav Petkov <bp@suse.de> Cc: Joerg Roedel <joro@8bytes.org> Cc: Kees Cook <keescook@chromium.org> Cc: Bjorn Helgaas <bhelgaas@google.com> Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1810082151160.2455@nanos.tec.linutronix.de
1 parent b69c2e2 commit c200dac

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

arch/x86/mm/dump_pagetables.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
#include <linux/sched.h>
2020
#include <linux/seq_file.h>
2121
#include <linux/highmem.h>
22+
#include <linux/pci.h>
2223

24+
#include <asm/e820/types.h>
2325
#include <asm/pgtable.h>
2426

2527
/*
@@ -241,6 +243,29 @@ static unsigned long normalize_addr(unsigned long u)
241243
return (signed long)(u << shift) >> shift;
242244
}
243245

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+
244269
/*
245270
* This function gets called on a break in a continuous series
246271
* 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,
276301
unsigned long delta;
277302
int width = sizeof(unsigned long) * 2;
278303

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);
287306

288307
/*
289308
* Now print the actual finished series

0 commit comments

Comments
 (0)