* [PATCH] riscv: check leaf entry alignment in pageattr_pxd_entry()
@ 2026-04-20 4:59 Austin Kim
0 siblings, 0 replies; only message in thread
From: Austin Kim @ 2026-04-20 4:59 UTC (permalink / raw)
To: Paul Walmsley, Palmer Dabbelt, Alexandre Ghiti
Cc: linux-riscv, linux-kernel, austindh.kim
During page table walking, ensure the range being processed matches
the expected size of a leaf entry (P4D, PUD, or PMD). While pxd_addr_end()
functions handle boundary checks, they do not inherently validate whether
the entry is a leaf node of the expected size.
Add WARN_ON_ONCE() to detect misalignments or partial updates of huge
pages. If a mismatch is detected, return -EINVAL to prevent potential
corruption of page table entries.
Signed-off-by: Austin Kim <austindh.kim@gmail.com>
---
arch/riscv/mm/pageattr.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/riscv/mm/pageattr.c b/arch/riscv/mm/pageattr.c
index 3f76db3d2..1461bf77f 100644
--- a/arch/riscv/mm/pageattr.c
+++ b/arch/riscv/mm/pageattr.c
@@ -32,6 +32,8 @@ static int pageattr_p4d_entry(p4d_t *p4d, unsigned long addr,
p4d_t val = p4dp_get(p4d);
if (p4d_leaf(val)) {
+ if (WARN_ON_ONCE((next - addr) != P4D_SIZE))
+ return -EINVAL;
val = __p4d(set_pageattr_masks(p4d_val(val), walk));
set_p4d(p4d, val);
}
@@ -45,6 +47,8 @@ static int pageattr_pud_entry(pud_t *pud, unsigned long addr,
pud_t val = pudp_get(pud);
if (pud_leaf(val)) {
+ if (WARN_ON_ONCE((next - addr) != PUD_SIZE))
+ return -EINVAL;
val = __pud(set_pageattr_masks(pud_val(val), walk));
set_pud(pud, val);
}
@@ -58,6 +62,8 @@ static int pageattr_pmd_entry(pmd_t *pmd, unsigned long addr,
pmd_t val = pmdp_get(pmd);
if (pmd_leaf(val)) {
+ if (WARN_ON_ONCE((next - addr) != PMD_SIZE))
+ return -EINVAL;
val = __pmd(set_pageattr_masks(pmd_val(val), walk));
set_pmd(pmd, val);
}
--
2.34.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-04-20 4:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-20 4:59 [PATCH] riscv: check leaf entry alignment in pageattr_pxd_entry() Austin Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox