linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: Laura Abbott <labbott@fedoraproject.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will.deacon@arm.com>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Kees Cook <keescook@chromium.org>,
	Xishi Qiu <qiuxishi@huawei.com>,
	Mark Rutland <mark.rutland@arm.com>
Subject: Re: [PATCH 2/2] arm64: Allow changing of attributes outside of modules
Date: Thu, 5 Nov 2015 08:44:44 +0100	[thread overview]
Message-ID: <CAKv+Gu-v2uQK6GbyVn2i2HMf-5S-k5_w1CodQtCr9gOuLcW01A@mail.gmail.com> (raw)
In-Reply-To: <1446587315-18145-3-git-send-email-labbott@fedoraproject.org>

On 3 November 2015 at 22:48, Laura Abbott <labbott@fedoraproject.org> wrote:
>
> Currently, the set_memory_* functions that are implemented for arm64
> are restricted to module addresses only. This was mostly done
> because arm64 maps normal zone memory with larger page sizes to
> improve TLB performance. This has the side effect though of making it
> difficult to adjust attributes at the PAGE_SIZE granularity. There are
> an increasing number of use cases related to security where it is
> necessary to change the attributes of kernel memory. Add functionality
> to the page attribute changing code under a Kconfig to let systems
> designers decide if they want to make the trade off of security for TLB
> pressure.
>
> Signed-off-by: Laura Abbott <labbott@fedoraproject.org>
> ---
>  arch/arm64/Kconfig.debug | 11 +++++++
>  arch/arm64/mm/mm.h       |  3 ++
>  arch/arm64/mm/mmu.c      |  2 +-
>  arch/arm64/mm/pageattr.c | 74 ++++++++++++++++++++++++++++++++++++++++++++----
>  4 files changed, 84 insertions(+), 6 deletions(-)
>
> diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug
> index d6285ef..abc6922 100644
> --- a/arch/arm64/Kconfig.debug
> +++ b/arch/arm64/Kconfig.debug
> @@ -89,6 +89,17 @@ config DEBUG_ALIGN_RODATA
>
>           If in doubt, say N
>
> +config DEBUG_CHANGE_PAGEATTR

I don't think this belongs in Kconfig.debug, and I don't think this
should default to off.

We know we currently have no users of set_memory_xx() in arch/arm64
that operate on linear mapping addresses, so we will not introduce any
performance regressions by adding this functionality now. By putting
this feature behind a debug option, every newly introduced call
set_memory_xx() that operates on linear or vmalloc() addresses needs
to deal with -EINVAL (or depend on DEBUG_CHANGE_PAGEATTR), or it may
error out at runtime if the feature is not enabled.

> +       bool "Allow all kernel memory to have attributes changed"
> +       help
> +         If this option is selected, APIs that change page attributes
> +         (RW <-> RO, X <-> NX) will be valid for all memory mapped in
> +         the kernel space. The trade off is that there may be increased
> +         TLB pressure from finer grained page mapping. Turn on this option
> +         if performance is more important than security
> +

This is backwards

> +         If in doubt, say N
> +
>  source "drivers/hwtracing/coresight/Kconfig"
>
>  endmenu

[...]

> diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
> index e47ed1c..48a4ce9 100644
> --- a/arch/arm64/mm/pageattr.c
> +++ b/arch/arm64/mm/pageattr.c

[...]

> @@ -45,17 +108,18 @@ static int change_memory_common(unsigned long addr, int numpages,
>         int ret;
>         struct page_change_data data;
>
> +       if (addr < PAGE_OFFSET && !is_vmalloc_addr((void *)addr))
> +               return -EINVAL;
> +

Doesn't this exclude the module area?

>         if (!IS_ALIGNED(addr, PAGE_SIZE)) {
>                 start &= PAGE_MASK;
>                 end = start + size;
>                 WARN_ON_ONCE(1);
>         }
>
> -       if (start < MODULES_VADDR || start >= MODULES_END)
> -               return -EINVAL;
> -
> -       if (end < MODULES_VADDR || end >= MODULES_END)
> -               return -EINVAL;
> +       ret = check_address(addr);
> +       if (ret)
> +               return ret;
>
>         data.set_mask = set_mask;
>         data.clear_mask = clear_mask;
> --
> 2.4.3
>

  parent reply	other threads:[~2015-11-05  7:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-03 21:48 [PATCH 0/2] Support for set_memory_* outside of module space Laura Abbott
2015-11-03 21:48 ` [PATCH 1/2] arm64: Get existing page protections in split_pmd Laura Abbott
2015-11-05  7:07   ` Ard Biesheuvel
2015-11-05 10:15   ` Xishi Qiu
2015-11-06  1:24     ` Laura Abbott
2015-11-03 21:48 ` [PATCH 2/2] arm64: Allow changing of attributes outside of modules Laura Abbott
2015-11-04  3:17   ` zhong jiang
2015-11-05  7:44   ` Ard Biesheuvel [this message]
2015-11-06  1:35     ` Laura Abbott
     [not found]   ` <563974A8.3060306@huawei.com>
     [not found]     ` <563A4A74.60900@redhat.com>
2015-11-05 11:10       ` Xishi Qiu
2015-11-06  1:11         ` Laura Abbott
2015-11-05 11:29   ` Xishi Qiu
2015-11-03 23:42 ` [PATCH 0/2] Support for set_memory_* outside of module space Kees Cook
2015-11-04 18:51   ` Laura Abbott
2015-11-04 19:06     ` Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKv+Gu-v2uQK6GbyVn2i2HMf-5S-k5_w1CodQtCr9gOuLcW01A@mail.gmail.com \
    --to=ard.biesheuvel@linaro.org \
    --cc=catalin.marinas@arm.com \
    --cc=keescook@chromium.org \
    --cc=labbott@fedoraproject.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=qiuxishi@huawei.com \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).