From: Austin Kim <austindh.kim@gmail.com>
To: Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Alexandre Ghiti <alex@ghiti.fr>
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
austindh.kim@gmail.com
Subject: [PATCH] riscv: check leaf entry alignment in pageattr_pxd_entry()
Date: Mon, 20 Apr 2026 13:59:36 +0900 [thread overview]
Message-ID: <aeWyuC3nXrP9McNy@adminpc-PowerEdge-R7525> (raw)
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
reply other threads:[~2026-04-20 4:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=aeWyuC3nXrP9McNy@adminpc-PowerEdge-R7525 \
--to=austindh.kim@gmail.com \
--cc=alex@ghiti.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
/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