[SRU][Bionic][PATCH] x86/mm: Do not warn about PCI BIOS W+X mappings

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[SRU][Bionic][PATCH] x86/mm: Do not warn about PCI BIOS W+X mappings

Juerg Haefliger
From: Thomas Gleixner <[hidden email]>

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 <[hidden email]>
Signed-off-by: Thomas Gleixner <[hidden email]>
Tested-by: Borislav Petkov <[hidden email]>
Cc: Joerg Roedel <[hidden email]>
Cc: Kees Cook <[hidden email]>
Cc: Bjorn Helgaas <[hidden email]>
Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1810082151160.2455@...

(cherry picked from commit c200dac78fec66d87ef262cac38cfe4feabdf737)
Signed-off-by: Juerg Haefliger <[hidden email]>
---
 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 <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>
 
 /*
@@ -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
--
2.19.1


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

Re: [SRU][Bionic][PATCH] x86/mm: Do not warn about PCI BIOS W+X mappings

Juerg Haefliger
This is for Cosmic, not Bionic.

...Juerg


> From: Thomas Gleixner <[hidden email]>
>
> 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 <[hidden email]>
> Signed-off-by: Thomas Gleixner <[hidden email]>
> Tested-by: Borislav Petkov <[hidden email]>
> Cc: Joerg Roedel <[hidden email]>
> Cc: Kees Cook <[hidden email]>
> Cc: Bjorn Helgaas <[hidden email]>
> Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1810082151160.2455@...
>
> (cherry picked from commit c200dac78fec66d87ef262cac38cfe4feabdf737)
> Signed-off-by: Juerg Haefliger <[hidden email]>
> ---
>  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 <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>
>  
>  /*
> @@ -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

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team

attachment0 (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

ACK/Cmnt: [SRU][Cosmic][PATCH] x86/mm: Do not warn about PCI BIOS W+X mappings

Stefan Bader-2
In reply to this post by Juerg Haefliger
On 28.01.19 15:12, Juerg Haefliger wrote:

> From: Thomas Gleixner <[hidden email]>
>
> 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 <[hidden email]>
> Signed-off-by: Thomas Gleixner <[hidden email]>
> Tested-by: Borislav Petkov <[hidden email]>
> Cc: Joerg Roedel <[hidden email]>
> Cc: Kees Cook <[hidden email]>
> Cc: Bjorn Helgaas <[hidden email]>
> Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1810082151160.2455@...
>
> (cherry picked from commit c200dac78fec66d87ef262cac38cfe4feabdf737)
> Signed-off-by: Juerg Haefliger <[hidden email]>
Acked-by: Stefan Bader <[hidden email]>
> ---

Noting the adjusted destination series.

>  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 <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>
>  
>  /*
> @@ -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
>


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

ACK/cmnt[Cosmic]: [SRU][Bionic][PATCH] x86/mm: Do not warn about PCI BIOS W+X mappings

Kleber Souza
In reply to this post by Juerg Haefliger
On 1/28/19 3:12 PM, Juerg Haefliger wrote:

> From: Thomas Gleixner <[hidden email]>
>
> 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 <[hidden email]>
> Signed-off-by: Thomas Gleixner <[hidden email]>
> Tested-by: Borislav Petkov <[hidden email]>
> Cc: Joerg Roedel <[hidden email]>
> Cc: Kees Cook <[hidden email]>
> Cc: Bjorn Helgaas <[hidden email]>
> Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1810082151160.2455@...
>
> (cherry picked from commit c200dac78fec66d87ef262cac38cfe4feabdf737)
> Signed-off-by: Juerg Haefliger <[hidden email]>

For *Cosmic*:

Acked-by: Kleber Sacilotto de Souza <[hidden email]>

> ---
>  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 <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>
>  
>  /*
> @@ -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



--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

APPLIED/Cmnt: [SRU][Bionic][PATCH] x86/mm: Do not warn about PCI BIOS W+X mappings

Stefan Bader-2
In reply to this post by Juerg Haefliger
On 28.01.19 15:12, Juerg Haefliger wrote:

> From: Thomas Gleixner <[hidden email]>
>
> 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 <[hidden email]>
> Signed-off-by: Thomas Gleixner <[hidden email]>
> Tested-by: Borislav Petkov <[hidden email]>
> Cc: Joerg Roedel <[hidden email]>
> Cc: Kees Cook <[hidden email]>
> Cc: Bjorn Helgaas <[hidden email]>
> Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1810082151160.2455@...
>
> (cherry picked from commit c200dac78fec66d87ef262cac38cfe4feabdf737)
> Signed-off-by: Juerg Haefliger <[hidden email]>
> ---
Actually was already applied together with those ACKs when the Bionic submission
was done. I checked whether this Cosmic version would cleanly reverse apply and
it did.


Applied to cosmic/master-next. Thanks.

-Stefan

>  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 <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>
>  
>  /*
> @@ -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
>


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team

signature.asc (849 bytes) Download Attachment