RE: [PATCH v6 03/11] mm, x86: Add support for eXclusive Page Frame Ownership (XPFO)

From: Ralph Campbell
Date: Thu Sep 07 2017 - 14:36:25 EST




> -----Original Message-----
> From: owner-linux-mm@xxxxxxxxx [mailto:owner-linux-mm@xxxxxxxxx] On
> Behalf Of Tycho Andersen
> Sent: Thursday, September 7, 2017 10:36 AM
> To: linux-kernel@xxxxxxxxxxxxxxx
> Cc: linux-mm@xxxxxxxxx; kernel-hardening@xxxxxxxxxxxxxxxxxx; Marco Benatto
> <marco.antonio.780@xxxxxxxxx>; Juerg Haefliger
> <juerg.haefliger@xxxxxxxxxxxxx>; x86@xxxxxxxxxx; Tycho Andersen
> <tycho@xxxxxxxxxx>
> Subject: [PATCH v6 03/11] mm, x86: Add support for eXclusive Page Frame
> Ownership (XPFO)
>
> From: Juerg Haefliger <juerg.haefliger@xxxxxxxxxxxxx>
>
> This patch adds support for XPFO which protects against 'ret2dir' kernel attacks.
> The basic idea is to enforce exclusive ownership of page frames by either the
> kernel or userspace, unless explicitly requested by the kernel. Whenever a page
> destined for userspace is allocated, it is unmapped from physmap (the kernel's
> page table). When such a page is reclaimed from userspace, it is mapped back to
> physmap.
>
> Additional fields in the page_ext struct are used for XPFO housekeeping,
> specifically:
> - two flags to distinguish user vs. kernel pages and to tag unmapped
> pages.
> - a reference counter to balance kmap/kunmap operations.
> - a lock to serialize access to the XPFO fields.
>
> This patch is based on the work of Vasileios P. Kemerlis et al. who published their
> work in this paper:
> http://www.cs.columbia.edu/~vpk/papers/ret2dir.sec14.pdf
>
> v6: * use flush_tlb_kernel_range() instead of __flush_tlb_one, so we flush
> the tlb entry on all CPUs when unmapping it in kunmap
> * handle lookup_page_ext()/lookup_xpfo() returning NULL
> * drop lots of BUG()s in favor of WARN()
> * don't disable irqs in xpfo_kmap/xpfo_kunmap, export
> __split_large_page so we can do our own alloc_pages(GFP_ATOMIC) to
> pass it
>
> CC: x86@xxxxxxxxxx
> Suggested-by: Vasileios P. Kemerlis <vpk@xxxxxxxxxxxxxxx>
> Signed-off-by: Juerg Haefliger <juerg.haefliger@xxxxxxxxxxxxx>
> Signed-off-by: Tycho Andersen <tycho@xxxxxxxxxx>
> Signed-off-by: Marco Benatto <marco.antonio.780@xxxxxxxxx>
> ---
> Documentation/admin-guide/kernel-parameters.txt | 2 +
> arch/x86/Kconfig | 1 +
> arch/x86/include/asm/pgtable.h | 25 +++
> arch/x86/mm/Makefile | 1 +
> arch/x86/mm/pageattr.c | 22 +--
> arch/x86/mm/xpfo.c | 114 ++++++++++++
> include/linux/highmem.h | 15 +-
> include/linux/xpfo.h | 42 +++++
> mm/Makefile | 1 +
> mm/page_alloc.c | 2 +
> mm/page_ext.c | 4 +
> mm/xpfo.c | 222 ++++++++++++++++++++++++
> security/Kconfig | 19 ++
> 13 files changed, 449 insertions(+), 21 deletions(-)
>
> diff --git a/Documentation/admin-guide/kernel-parameters.txt
> b/Documentation/admin-guide/kernel-parameters.txt
> index d9c171ce4190..444d83183f75 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -2736,6 +2736,8 @@
>
> nox2apic [X86-64,APIC] Do not enable x2APIC mode.
>
> + noxpfo [X86-64] Disable XPFO when CONFIG_XPFO is on.
> +
> cpu0_hotplug [X86] Turn on CPU0 hotplug feature when
> CONFIG_BOOTPARAM_HOTPLUG_CPU0 is off.
> Some features depend on CPU0. Known dependencies
<... snip>

A bit more description for system administrators would be very useful.
Perhaps something like:

noxpfo [XPFO,X86-64] Disable eXclusive Page Frame Ownership (XPFO)
Physical pages mapped into user applications will also be mapped
in the kernel's address space as if CONFIG_XPFO was not enabled.

Patch 05 should also update kernel-parameters.txt and add "ARM64" to the config option list for noxpfo.