[PATCH v10 4/5] arm64: ptdump: Don't override the level when operating on the stage-2 tables

Sebastian Ene posted 5 patches 2 months, 3 weeks ago
[PATCH v10 4/5] arm64: ptdump: Don't override the level when operating on the stage-2 tables
Posted by Sebastian Ene 2 months, 3 weeks ago
Ptdump uses the init_mm structure directly to dump the kernel
pagetables. When ptdump is called on the stage-2 pagetables, this mm
argument is not used. Prevent the level from being overwritten by
checking the argument against NULL.

Signed-off-by: Sebastian Ene <sebastianene@google.com>
---
 arch/arm64/mm/ptdump.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c
index ca53ef274a8b..264c5f9b97d8 100644
--- a/arch/arm64/mm/ptdump.c
+++ b/arch/arm64/mm/ptdump.c
@@ -197,8 +197,8 @@ void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
 	u64 prot = 0;
 
 	/* check if the current level has been folded dynamically */
-	if ((level == 1 && mm_p4d_folded(st->mm)) ||
-	    (level == 2 && mm_pud_folded(st->mm)))
+	if (st->mm && ((level == 1 && mm_p4d_folded(st->mm)) ||
+	    (level == 2 && mm_pud_folded(st->mm))))
 		level = 0;
 
 	if (level >= 0)
-- 
2.46.0.469.g59c65b2a67-goog
Re: [PATCH v10 4/5] arm64: ptdump: Don't override the level when operating on the stage-2 tables
Posted by Will Deacon 2 months, 3 weeks ago
On Mon, Sep 09, 2024 at 12:47:20PM +0000, Sebastian Ene wrote:
> Ptdump uses the init_mm structure directly to dump the kernel
> pagetables. When ptdump is called on the stage-2 pagetables, this mm
> argument is not used. Prevent the level from being overwritten by
> checking the argument against NULL.
> 
> Signed-off-by: Sebastian Ene <sebastianene@google.com>
> ---
>  arch/arm64/mm/ptdump.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Acked-by: Will Deacon <will@kernel.org>

Will