On Mon, Oct 8, 2018 at 12:53 PM, Thomas Gleixner <t...@linutronix.de> wrote: > 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. > > Reported-by: Paul Menzel <pmen...@molgen.mpg.de> > Signed-off-by: Thomas Gleixner <t...@linutronix.de> > Cc: Joerg Roedel <j...@8bytes.org> > Cc: Kees Cook <keesc...@chromium.org> > Cc: Bjorn Helgaas <bhelg...@google.com> > --- > arch/x86/mm/dump_pagetables.c | 35 +++++++++++++++++++++++++++-------- > 1 file changed, 27 insertions(+), 8 deletions(-) > > --- a/arch/x86/mm/dump_pagetables.c > +++ b/arch/x86/mm/dump_pagetables.c > @@ -19,7 +19,9 @@ > #include <linux/sched.h> > #include <linux/seq_file.h> > #include <linux/highmem.h> > +#include <linux/pci.h> > > +#include <asm/e820/types.h> > #include <asm/pgtable.h> > > /* > @@ -241,6 +243,29 @@ static unsigned long normalize_addr(unsi > return (signed long)(u << shift) >> shift; > } > > +static void note_wx(struct pg_state *st) > +{ > + unsigned long npages; > + > + npages = (st->current_address - st->start_address) / PAGE_SIZE; > + > +#ifdef CONFIG_PCI_BIOS > + /* > + * If PCI BIOS is enabled, the PCI BIOS area is forced to WX. > + * Inform about it, but avoid the warning. > + */ > + if (pcibios_enabled && st->start_address >= PAGE_OFFSET + BIOS_BEGIN > && > + st->current_address <= PAGE_OFFSET + BIOS_END) { > + pr_warn_once("x86/mm: PCI BIOS W+X mapping %lu pages\n", > npages); > + return; > + } > +#endif > + /* Account the WX pages */ > + st->wx_pages += npages; > + WARN_ONCE(1, "x86/mm: Found insecure W+X mapping at address %p/%pS\n", > + (void *)st->start_address, (void *)st->start_address);
Probably we should just drop the "%p/" part. %pS should give us everything we need and %p will be meaningless normally. Otherwise, yes, this look good. -Kees -- Kees Cook Pixel Security