Linux Hardening
 help / color / mirror / Atom feed
From: Kevin Brodsky <kevin.brodsky@arm.com>
To: Dave Hansen <dave.hansen@intel.com>, linux-hardening@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Mark Brown <broonie@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Jann Horn <jannh@google.com>, Jeff Xu <jeffxu@chromium.org>,
	Joey Gouly <joey.gouly@arm.com>, Kees Cook <kees@kernel.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	Andy Lutomirski <luto@kernel.org>, Marc Zyngier <maz@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Pierre Langlois <pierre.langlois@arm.com>,
	Quentin Perret <qperret@google.com>,
	"Mike Rapoport (IBM)" <rppt@kernel.org>,
	Ryan Roberts <ryan.roberts@arm.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Will Deacon <will@kernel.org>,
	Matthew Wilcox <willy@infradead.org>,
	Qi Zheng <zhengqi.arch@bytedance.com>,
	linux-arm-kernel@lists.infradead.org, x86@kernel.org
Subject: Re: [RFC PATCH v2 00/15] pkeys-based page table hardening
Date: Mon, 13 Jan 2025 11:10:34 +0100	[thread overview]
Message-ID: <83b57cc5-fe6f-483b-b7e3-8d6e356c914f@arm.com> (raw)
In-Reply-To: <dcc1800c-cf0a-4d88-bc88-982f0709b382@intel.com>

On 09/01/2025 17:30, Dave Hansen wrote:
> One of the sticker things in the x86 attempt to do the same thing was
> context switching, both between normal tasks and in/out of exceptions
> and interrupts.
>
> The easiest place this manifested for us was code chunk like this:
>
> 	kpkeys_set_level(KPKEYS_LVL_PGTABLES);
> 	// modify page tables here
> 	kpkeys_restore_pkey_reg();
>
> We had to make sure that we didn't get preempted and context switch over
> to some other task that _wasn't_ doing page table manipulation while
> page table writes were allowed.
>
> On x86, we had to basically start context-switching the kernel pkey
> register the same way we do GPRs.
>
> How is SYS_POR_EL0 being context switched?

I think this is pretty much the same situation with POR_EL1 on arm64. I
mentioned on the cover letter that resetting POR_EL1 on exception entry
is required (and not done yet), but in fact as you say it also needs to
be context-switched per-thread. This does sound pretty similar to GPRs
(unlike POR_EL0, which is switched in __switch_to() like the user TLS
register for instance).

Is there a particular concern about that extra switching? I don't expect
it to be a significant cost on arm64. In the vast majority of cases,
POR_EL1 will remain set to its default value, meaning that the overhead
is limited to reading POR_EL1, a load and a branch. The only situation
where an expensive write to POR_EL1 is needed is an interrupt firing
right in the middle of a page table setter - possible but pretty
unlikely. Writing to POR_EL1 on exception return isn't really a concern
either, as no additional barrier (ISB) is required in that case.

By the way thank your for mentioning the x86 attempt, I wasn't aware of
it. I'll have a better look and make sure to Cc anyone involved in that
work in future versions.

- Kevin

      reply	other threads:[~2025-01-13 10:10 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-08 10:32 [RFC PATCH v2 00/15] pkeys-based page table hardening Kevin Brodsky
2025-01-08 10:32 ` [RFC PATCH v2 01/15] mm: Introduce kpkeys Kevin Brodsky
2025-01-08 10:32 ` [RFC PATCH v2 02/15] set_memory: Introduce set_memory_pkey() stub Kevin Brodsky
2025-01-08 10:32 ` [RFC PATCH v2 03/15] arm64: mm: Enable overlays for all EL1 indirect permissions Kevin Brodsky
2025-01-08 10:32 ` [RFC PATCH v2 04/15] arm64: Introduce por_set_pkey_perms() helper Kevin Brodsky
2025-01-08 10:32 ` [RFC PATCH v2 05/15] arm64: Implement asm/kpkeys.h using POE Kevin Brodsky
2025-01-08 10:32 ` [RFC PATCH v2 06/15] arm64: set_memory: Implement set_memory_pkey() Kevin Brodsky
2025-01-08 10:32 ` [RFC PATCH v2 07/15] arm64: Enable kpkeys Kevin Brodsky
2025-01-08 10:32 ` [RFC PATCH v2 08/15] mm: Introduce kernel_pgtables_set_pkey() Kevin Brodsky
2025-01-08 10:32 ` [RFC PATCH v2 09/15] mm: Introduce kpkeys_hardened_pgtables Kevin Brodsky
2025-01-08 10:32 ` [RFC PATCH v2 10/15] mm: Allow __pagetable_ctor() to fail Kevin Brodsky
2025-01-08 10:32 ` [RFC PATCH v2 11/15] mm: Map page tables with privileged pkey Kevin Brodsky
2025-01-08 10:32 ` [RFC PATCH v2 12/15] arm64: kpkeys: Support KPKEYS_LVL_PGTABLES Kevin Brodsky
2025-01-08 10:32 ` [RFC PATCH v2 13/15] arm64: mm: Guard page table writes with kpkeys Kevin Brodsky
2025-01-09  7:17   ` Qi Zheng
2025-01-10 14:05     ` Kevin Brodsky
2025-01-08 10:32 ` [RFC PATCH v2 14/15] arm64: Enable kpkeys_hardened_pgtables support Kevin Brodsky
2025-01-08 10:32 ` [RFC PATCH v2 15/15] mm: Add basic tests for kpkeys_hardened_pgtables Kevin Brodsky
2025-01-09 16:30 ` [RFC PATCH v2 00/15] pkeys-based page table hardening Dave Hansen
2025-01-13 10:10   ` Kevin Brodsky [this message]

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=83b57cc5-fe6f-483b-b7e3-8d6e356c914f@arm.com \
    --to=kevin.brodsky@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=dave.hansen@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=jannh@google.com \
    --cc=jeffxu@chromium.org \
    --cc=joey.gouly@arm.com \
    --cc=kees@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=maz@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pierre.langlois@arm.com \
    --cc=qperret@google.com \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=tglx@linutronix.de \
    --cc=will@kernel.org \
    --cc=willy@infradead.org \
    --cc=x86@kernel.org \
    --cc=zhengqi.arch@bytedance.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