From nobody Tue Feb 10 14:49:45 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2BF2B293B4C for ; Fri, 11 Apr 2025 09:17:50 +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=1744363072; cv=none; b=RNWfkQoahH52QngyRVHzpoZ9PlJfhlqm/9ANbM/r+dnafcMKUXZZv+3u6cewmKZfxIW6N0VQX+/1gj5O/MTk+/KqYYQSnV5zyF5pzEzJxzE02KPvF77libSICqDRx06EEbZdx81EbZNsmOH7vdFffYEPTy0C0xyPUUT9eLK0mIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744363072; c=relaxed/simple; bh=/G8IG1xZPxtDHV7DySv4e/zsqlpmhImnBbQtUfTIgE0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nmdzl7ZTB06By8E8+RbzWcJaYH2skAEV+Hn97V1wn0UKqbwnKFMHg22tRKxj730G6yGOa2URkQqa+7dTXY2WiOTAihrk5lJaYZLezzzqVa+QEPeA2l+yJNQVs+IZNjPf1bqE73eGRRIZI54o9TinBZtnNquJsWivLT0TES4bIUA= 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 44125106F; Fri, 11 Apr 2025 02:17:50 -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 B0DF23F6A8; Fri, 11 Apr 2025 02:17:46 -0700 (PDT) From: Kevin Brodsky To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Andrew Morton , Mark Brown , Catalin Marinas , Dave Hansen , David Hildenbrand , Ira Weiny , Jann Horn , Jeff Xu , Joey Gouly , Kees Cook , Linus Walleij , Andy Lutomirski , Marc Zyngier , Peter Zijlstra , Pierre Langlois , Quentin Perret , Rick Edgecombe , "Mike Rapoport (IBM)" , Ryan Roberts , Thomas Gleixner , Will Deacon , Matthew Wilcox , Qi Zheng , linux-arm-kernel@lists.infradead.org, x86@kernel.org Subject: [RFC PATCH v4 13/18] mm: Map page tables with privileged pkey Date: Fri, 11 Apr 2025 10:16:26 +0100 Message-ID: <20250411091631.954228-14-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250411091631.954228-1-kevin.brodsky@arm.com> References: <20250411091631.954228-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 43e35d41b850..411707dabe65 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -33,6 +33,7 @@ #include #include #include +#include =20 struct mempolicy; struct anon_vma; @@ -3083,6 +3084,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 @@ -3093,6 +3096,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