From patchwork Mon Jan 28 14:12:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juerg Haefliger X-Patchwork-Id: 1031939 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 43pBRj5qtTz9s7T; Tue, 29 Jan 2019 01:13:05 +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 1go7ei-0003It-DR; Mon, 28 Jan 2019 14:12:56 +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 1go7eg-0003Ie-6j for kernel-team@lists.ubuntu.com; Mon, 28 Jan 2019 14:12:54 +0000 Received: from mail-ed1-f71.google.com ([209.85.208.71]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1go7ef-0003yN-Vk for kernel-team@lists.ubuntu.com; Mon, 28 Jan 2019 14:12:53 +0000 Received: by mail-ed1-f71.google.com with SMTP id i55so6684327ede.14 for ; Mon, 28 Jan 2019 06:12:53 -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=6bmR+kbdeNyWH4yxEhbvCpmNWP2a8FSz+7NmLiNC6gg=; b=FIQAkE3sb9njaMBtHCnhfZlQDwRhw3ulImUMVsZHFhliG0lUY9cQOPAzgJTzT5KyJ7 UzsqlHRRIF4HKQnBwJfYSp48ZtTwVLAuhIvd6Isi/LWv7x5i/IG+YpFY8D0EURwAt5my D2xBkmORpuOCLrCbBf8j72YWUYaQjgE5p+67fzcnM8H7Mq0l1sIuyJtQ/K6mRNcOHmrj seAvu9TfaSnLZRUqtQ+JRmYczbniNmv/Rgydwj8YBzvdGvG7PWeyP4VArXAh8iJ1t7b3 zqzZKTr/hKHNn8RfHe588np7B6hgx/HM1+RlHKKnslQ4Tcuy2V2Lyb+2nA2yrW8uIc1B QQPQ== X-Gm-Message-State: AJcUukeD/0k2NXEkNZIdE6Gk8tT5DWr5402yFOQ7DpS06Y/QmnKT0p2V CnNk9wK1GlSW8B3RTDs+HtLbR7t47ldHggdaAcVtVSkfSVI9grghoeSGNz8bLUhCG6PdhSuLxI1 JnFjxOhqe5UGjF83ivTYw1QOV4/29syH0iTD/b86FVQ== X-Received: by 2002:a17:906:f212:: with SMTP id gt18mr19528687ejb.201.1548684773320; Mon, 28 Jan 2019 06:12:53 -0800 (PST) X-Google-Smtp-Source: ALg8bN5OI6Cw77SOfN3op/h3H0SEFu558DoavPgq9DabVifz/tNRjXetWnKfdSPrR1ZrFlehY1Tfsg== X-Received: by 2002:a17:906:f212:: with SMTP id gt18mr19528663ejb.201.1548684772956; Mon, 28 Jan 2019 06:12:52 -0800 (PST) Received: from gollum.fritz.box ([81.221.192.120]) by smtp.gmail.com with ESMTPSA id r8sm13159973edo.11.2019.01.28.06.12.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 06:12:52 -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 15:12:51 +0100 Message-Id: <20190128141251.28094-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 (cherry picked from commit c200dac78fec66d87ef262cac38cfe4feabdf737) Signed-off-by: Juerg Haefliger Acked-by: Stefan Bader Acked-by: Kleber Sacilotto de Souza --- 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 2f3c9196b834..587196cec335 100644 --- a/arch/x86/mm/dump_pagetables.c +++ b/arch/x86/mm/dump_pagetables.c @@ -19,7 +19,9 @@ #include #include #include +#include +#include #include /* @@ -231,6 +233,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 @@ -266,14 +291,8 @@ static void note_page(struct seq_file *m, struct pg_state *st, unsigned long delta; int width = sizeof(unsigned long) * 2; - if (st->check_wx && (eff & _PAGE_RW) && !(eff & _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 && (eff & _PAGE_RW) && !(eff & _PAGE_NX)) + note_wx(st); /* * Now print the actual finished series