From nobody Sat Oct 4 15:59:04 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 422AF2EA17D; Fri, 15 Aug 2025 08:56:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755248191; cv=none; b=E2jJ52JY2qKE3mGIst39e2xtiaxJhc8aYNhnn0BUWGBPtwJD/YyodV34yOqrE86ZrM6a5bScN2NmO7mJ9A8Bs3p2uuK2E6DGLj2fBBHwzEe51lRTDEQn9naESBM1l6jt3EYMH5+KVJKx05KcDQMkg9o8fHGW6o5aHAXN8H4eQzY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755248191; c=relaxed/simple; bh=ToXBWOgGTz8chhNsAvevUA/c/HXTQ5KBWXpirOIkp70=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gZCGi4A7u4lptLxgUvSGDFL4LEDer2wXLVOjOESnd94YWqPcEw2ZT45V29TgdJDsQYWRMZl7kzz92LNljxFUB1A5Fn/fZD3OIVsmIYf5REGuwj/nPjmThSMKsjM5NeXENcrJZrwXZt/Zjiy7G77QSLOeOV8upFDnW8N5RaFljA8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 72FCD1688; Fri, 15 Aug 2025 01:56:21 -0700 (PDT) Received: from e123572-lin.arm.com (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 053E83F63F; Fri, 15 Aug 2025 01:56:24 -0700 (PDT) From: Kevin Brodsky To: linux-hardening@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Andrew Morton , Andy Lutomirski , Catalin Marinas , Dave Hansen , David Hildenbrand , Ira Weiny , Jann Horn , Jeff Xu , Joey Gouly , Kees Cook , Linus Walleij , Lorenzo Stoakes , Marc Zyngier , Mark Brown , Matthew Wilcox , Maxwell Bland , "Mike Rapoport (IBM)" , Peter Zijlstra , Pierre Langlois , Quentin Perret , Rick Edgecombe , Ryan Roberts , Thomas Gleixner , Vlastimil Babka , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, x86@kernel.org Subject: [RFC PATCH v5 13/18] mm: Map page tables with privileged pkey Date: Fri, 15 Aug 2025 09:55:07 +0100 Message-ID: <20250815085512.2182322-14-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250815085512.2182322-1-kevin.brodsky@arm.com> References: <20250815085512.2182322-1-kevin.brodsky@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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 #include #include +#include =20 struct mempolicy; struct anon_vma; @@ -2979,6 +2980,8 @@ static inline bool __pagetable_ctor(struct ptdesc *pt= desc) =20 __folio_set_pgtable(folio); lruvec_stat_add_folio(folio, NR_PAGETABLE); + if (kpkeys_protect_pgtable_memory(folio)) + return false; return true; } =20 @@ -2989,6 +2992,7 @@ static inline void pagetable_dtor(struct ptdesc *ptde= sc) ptlock_free(ptdesc); __folio_clear_pgtable(folio); lruvec_stat_sub_folio(folio, NR_PAGETABLE); + kpkeys_unprotect_pgtable_memory(folio); } =20 static inline void pagetable_dtor_free(struct ptdesc *ptdesc) --=20 2.47.0