From patchwork Mon Jan 28 13:06:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juerg Haefliger X-Patchwork-Id: 1031906 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43p8z71M5Tz9s7h; Tue, 29 Jan 2019 00:06:43 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1go6cT-0005Ca-W4; Mon, 28 Jan 2019 13:06:33 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1go6cR-0005CH-CC for kernel-team@lists.ubuntu.com; Mon, 28 Jan 2019 13:06:31 +0000 Received: from mail-ed1-f70.google.com ([209.85.208.70]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1go6cQ-0007yM-Tk for kernel-team@lists.ubuntu.com; Mon, 28 Jan 2019 13:06:30 +0000 Received: by mail-ed1-f70.google.com with SMTP id c34so6449236edb.8 for ; Mon, 28 Jan 2019 05:06:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=eGcPWCiZXBsjMZ8P9KuryTOfua1FacI3OuOUrxDsXfc=; b=iJ/5Ma4NQO3pcgFM/TI2hRTsWbaQuV1KWRt7w4nYLGcNXK+6/iRx0XwQfKcTBuRbti 47inTUDmVV8lUJh64Ih+3v24R560f5h5nIyfPXGKY+3pP8xBcZhpD9i/KGHLtuL1R91t NbTn5NXJXmsMhzG/RdcH21w9+mi/gXR9iWFXM7sI7BFMAIGq8FIZUJkKM9jZRC6jCXmX PaztxLFNRj2aC4J2zvv9ovkih8fxIa4Hi13/xLh5uT8F0tmQP1g2UJE3usQFfFtvhSdc CYFxR0x4rYW5vOTeLtgNEZ6MuCUrh6d7OF9IG9jiJJ6bbJtlA2UxSfrqi7oO5tDBbS3n S/dA== X-Gm-Message-State: AJcUukclWsQJPiI0tECbc5jdKxkLRjCPqwbb1OAFSipjSjGxzkMHgZui 3i1uMY94WYFh+vHeVoTymFSbBRBkDN79O2DJSWyItqIQMZHsF0CFyt+14jD2a7Y8NCWylGuDpGD 3IUsabP6X39b5PfWKbmROX9aZKuYlKGzWrJaZyyU4Bg== X-Received: by 2002:a17:906:3b09:: with SMTP id g9mr17880118ejf.166.1548680790255; Mon, 28 Jan 2019 05:06:30 -0800 (PST) X-Google-Smtp-Source: ALg8bN4/MhTW9eu01PSQgH98LT9pwL2VTSV50voQ+ws19uyQe9Qd4DFH68jHTSvO3bIEdKR2JjgNvQ== X-Received: by 2002:a17:906:3b09:: with SMTP id g9mr17880100ejf.166.1548680789887; Mon, 28 Jan 2019 05:06:29 -0800 (PST) Received: from gollum.fritz.box ([81.221.192.120]) by smtp.gmail.com with ESMTPSA id t9sm13846676edd.25.2019.01.28.05.06.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 05:06:29 -0800 (PST) From: Juerg Haefliger X-Google-Original-From: Juerg Haefliger To: kernel-team@lists.ubuntu.com Subject: [SRU][Bionic][PATCH] x86/mm: Do not warn about PCI BIOS W+X mappings Date: Mon, 28 Jan 2019 14:06:28 +0100 Message-Id: <20190128130628.12149-1-juergh@canonical.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Thomas Gleixner BugLink: https://bugs.launchpad.net/bugs/1813532 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 Signed-off-by: Thomas Gleixner Tested-by: Borislav Petkov Cc: Joerg Roedel Cc: Kees Cook Cc: Bjorn Helgaas Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1810082151160.2455@nanos.tec.linutronix.de (backported from commit c200dac78fec66d87ef262cac38cfe4feabdf737) [juergh: Adjusted context.] Signed-off-by: Juerg Haefliger Acked-by: Colin Ian King Acked-by: Stefan Bader --- arch/x86/mm/dump_pagetables.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c index 2a4849e92831..c9b50a5b7942 100644 --- a/arch/x86/mm/dump_pagetables.c +++ b/arch/x86/mm/dump_pagetables.c @@ -18,7 +18,9 @@ #include #include #include +#include +#include #include /* @@ -225,6 +227,29 @@ static unsigned long normalize_addr(unsigned long u) 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 %pS\n", + (void *)st->start_address); +} + /* * This function gets called on a break in a continuous series * of PTE entries; the next one is different so we need to @@ -259,14 +284,8 @@ static void note_page(struct seq_file *m, struct pg_state *st, int width = sizeof(unsigned long) * 2; pgprotval_t pr = pgprot_val(st->current_prot); - if (st->check_wx && (pr & _PAGE_RW) && !(pr & _PAGE_NX)) { - WARN_ONCE(1, - "x86/mm: Found insecure W+X mapping at address %p/%pS\n", - (void *)st->start_address, - (void *)st->start_address); - st->wx_pages += (st->current_address - - st->start_address) / PAGE_SIZE; - } + if (st->check_wx && (pr & _PAGE_RW) && !(pr & _PAGE_NX)) + note_wx(st); /* * Now print the actual finished series