[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <48ed62b1-cceb-4bce-923c-25c11dbccc37@redhat.com>
Date: Wed, 1 Oct 2025 17:28:47 +0200
From: David Hildenbrand <david@...hat.com>
To: Kevin Brodsky <kevin.brodsky@....com>, linux-hardening@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, Andrew Morton <akpm@...ux-foundation.org>,
Andy Lutomirski <luto@...nel.org>, Catalin Marinas
<catalin.marinas@....com>, Dave Hansen <dave.hansen@...ux.intel.com>,
Ira Weiny <ira.weiny@...el.com>, Jann Horn <jannh@...gle.com>,
Jeff Xu <jeffxu@...omium.org>, Joey Gouly <joey.gouly@....com>,
Kees Cook <kees@...nel.org>, Linus Walleij <linus.walleij@...aro.org>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>, Marc Zyngier <maz@...nel.org>,
Mark Brown <broonie@...nel.org>, Matthew Wilcox <willy@...radead.org>,
Maxwell Bland <mbland@...orola.com>, "Mike Rapoport (IBM)"
<rppt@...nel.org>, Peter Zijlstra <peterz@...radead.org>,
Pierre Langlois <pierre.langlois@....com>,
Quentin Perret <qperret@...gle.com>,
Rick Edgecombe <rick.p.edgecombe@...el.com>,
Ryan Roberts <ryan.roberts@....com>, Thomas Gleixner <tglx@...utronix.de>,
Vlastimil Babka <vbabka@...e.cz>, Will Deacon <will@...nel.org>,
linux-arm-kernel@...ts.infradead.org, linux-mm@...ck.org, x86@...nel.org
Subject: Re: [RFC PATCH v5 13/18] mm: Map page tables with privileged pkey
On 15.08.25 10:55, Kevin Brodsky wrote:
Just wondering, should the patch subject be:
"mm: protect page tables with privileged pkey" ?
At least patch #2 tells me that set_memory_pkey() will set the
protection key, and the function is called "kpkeys_protect_pgtable_memory"?
Just trying to connect the dots here :)
> If CONFIG_KPKEYS_HARDENED_PGTABLES is enabled, map allocated page
> table pages using a privileged pkey (KPKEYS_PKEY_PGTABLES), so that
> page tables can only be written under guard(kpkeys_hardened_pgtables).
>
> This patch is a no-op if CONFIG_KPKEYS_HARDENED_PGTABLES is disabled
> (default).
>
> Signed-off-by: Kevin Brodsky <kevin.brodsky@....com>
> ---
> include/linux/mm.h | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index d9371d992033..4880cb7a4cb9 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -34,6 +34,7 @@
> #include <linux/slab.h>
> #include <linux/cacheinfo.h>
> #include <linux/rcuwait.h>
> +#include <linux/kpkeys.h>
>
> struct mempolicy;
> struct anon_vma;
> @@ -2979,6 +2980,8 @@ static inline bool __pagetable_ctor(struct ptdesc *ptdesc)
>
> __folio_set_pgtable(folio);
> lruvec_stat_add_folio(folio, NR_PAGETABLE);
> + if (kpkeys_protect_pgtable_memory(folio))
> + return false;
> return true;
> }
>
> @@ -2989,6 +2992,7 @@ static inline void pagetable_dtor(struct ptdesc *ptdesc)
> ptlock_free(ptdesc);
> __folio_clear_pgtable(folio);
> lruvec_stat_sub_folio(folio, NR_PAGETABLE);
> + kpkeys_unprotect_pgtable_memory(folio);
This is all rather nasty. Not your fault.
In the near future page tables will not be folios, and the whole
ptdesc_folio() conversion will not make any sense.
Likely you should make kpkeys_protect_pgtable_memory() etc. consume an
address range, or a page range right from the start.
--
Cheers
David / dhildenb
Powered by blists - more mailing lists