Commit 6cdc82db authored by Christophe Leroy's avatar Christophe Leroy Committed by Andrew Morton

mm: ptdump: have ptdump_check_wx() return bool

Have ptdump_check_wx() return true when the check is successful or false
otherwise.

[akpm@linux-foundation.org: fix a couple of build issues (x86_64 allmodconfig)]
Link: https://lkml.kernel.org/r/7943149fe955458cb7b57cd483bf41a3aad94684.1706610398.git.christophe.leroy@csgroup.euSigned-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: "Aneesh Kumar K.V (IBM)" <aneesh.kumar@kernel.org>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Greg KH <greg@kroah.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: "Naveen N. Rao" <naveen.n.rao@linux.ibm.com>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Phong Tran <tranmanphong@gmail.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Steven Price <steven.price@arm.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 592e15f6
...@@ -345,7 +345,7 @@ static struct ptdump_info kernel_ptdump_info = { ...@@ -345,7 +345,7 @@ static struct ptdump_info kernel_ptdump_info = {
.base_addr = PAGE_OFFSET, .base_addr = PAGE_OFFSET,
}; };
void ptdump_check_wx(void) bool ptdump_check_wx(void)
{ {
struct pg_state st = { struct pg_state st = {
.seq = NULL, .seq = NULL,
...@@ -366,11 +366,16 @@ void ptdump_check_wx(void) ...@@ -366,11 +366,16 @@ void ptdump_check_wx(void)
ptdump_walk_pgd(&st.ptdump, &init_mm, NULL); ptdump_walk_pgd(&st.ptdump, &init_mm, NULL);
if (st.wx_pages || st.uxn_pages) if (st.wx_pages || st.uxn_pages) {
pr_warn("Checked W+X mappings: FAILED, %lu W+X pages found, %lu non-UXN pages found\n", pr_warn("Checked W+X mappings: FAILED, %lu W+X pages found, %lu non-UXN pages found\n",
st.wx_pages, st.uxn_pages); st.wx_pages, st.uxn_pages);
else
return false;
} else {
pr_info("Checked W+X mappings: passed, no W+X pages found\n"); pr_info("Checked W+X mappings: passed, no W+X pages found\n");
return true;
}
} }
static int __init ptdump_init(void) static int __init ptdump_init(void)
......
...@@ -327,7 +327,7 @@ static void __init build_pgtable_complete_mask(void) ...@@ -327,7 +327,7 @@ static void __init build_pgtable_complete_mask(void)
pg_level[i].mask |= pg_level[i].flag[j].mask; pg_level[i].mask |= pg_level[i].flag[j].mask;
} }
void ptdump_check_wx(void) bool ptdump_check_wx(void)
{ {
struct pg_state st = { struct pg_state st = {
.seq = NULL, .seq = NULL,
...@@ -344,15 +344,20 @@ void ptdump_check_wx(void) ...@@ -344,15 +344,20 @@ void ptdump_check_wx(void)
}; };
if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && !mmu_has_feature(MMU_FTR_KERNEL_RO)) if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && !mmu_has_feature(MMU_FTR_KERNEL_RO))
return; return true;
ptdump_walk_pgd(&st.ptdump, &init_mm, NULL); ptdump_walk_pgd(&st.ptdump, &init_mm, NULL);
if (st.wx_pages) if (st.wx_pages) {
pr_warn("Checked W+X mappings: FAILED, %lu W+X pages found\n", pr_warn("Checked W+X mappings: FAILED, %lu W+X pages found\n",
st.wx_pages); st.wx_pages);
else
return false;
} else {
pr_info("Checked W+X mappings: passed, no W+X pages found\n"); pr_info("Checked W+X mappings: passed, no W+X pages found\n");
return true;
}
} }
static int __init ptdump_init(void) static int __init ptdump_init(void)
......
...@@ -335,7 +335,7 @@ static void ptdump_walk(struct seq_file *s, struct ptd_mm_info *pinfo) ...@@ -335,7 +335,7 @@ static void ptdump_walk(struct seq_file *s, struct ptd_mm_info *pinfo)
ptdump_walk_pgd(&st.ptdump, pinfo->mm, NULL); ptdump_walk_pgd(&st.ptdump, pinfo->mm, NULL);
} }
void ptdump_check_wx(void) bool ptdump_check_wx(void)
{ {
struct pg_state st = { struct pg_state st = {
.seq = NULL, .seq = NULL,
...@@ -356,11 +356,16 @@ void ptdump_check_wx(void) ...@@ -356,11 +356,16 @@ void ptdump_check_wx(void)
ptdump_walk_pgd(&st.ptdump, &init_mm, NULL); ptdump_walk_pgd(&st.ptdump, &init_mm, NULL);
if (st.wx_pages) if (st.wx_pages) {
pr_warn("Checked W+X mappings: failed, %lu W+X pages found\n", pr_warn("Checked W+X mappings: failed, %lu W+X pages found\n",
st.wx_pages); st.wx_pages);
else
return false;
} else {
pr_info("Checked W+X mappings: passed, no W+X pages found\n"); pr_info("Checked W+X mappings: passed, no W+X pages found\n");
return true;
}
} }
static int ptdump_show(struct seq_file *m, void *v) static int ptdump_show(struct seq_file *m, void *v)
......
...@@ -192,7 +192,7 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, ...@@ -192,7 +192,7 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
} }
} }
void ptdump_check_wx(void) bool ptdump_check_wx(void)
{ {
struct pg_state st = { struct pg_state st = {
.ptdump = { .ptdump = {
...@@ -215,14 +215,19 @@ void ptdump_check_wx(void) ...@@ -215,14 +215,19 @@ void ptdump_check_wx(void)
}; };
if (!MACHINE_HAS_NX) if (!MACHINE_HAS_NX)
return; return true;
ptdump_walk_pgd(&st.ptdump, &init_mm, NULL); ptdump_walk_pgd(&st.ptdump, &init_mm, NULL);
if (st.wx_pages) if (st.wx_pages) {
pr_warn("Checked W+X mappings: FAILED, %lu W+X pages found\n", st.wx_pages); pr_warn("Checked W+X mappings: FAILED, %lu W+X pages found\n", st.wx_pages);
else
return false;
} else {
pr_info("Checked W+X mappings: passed, no %sW+X pages found\n", pr_info("Checked W+X mappings: passed, no %sW+X pages found\n",
(nospec_uses_trampoline() || !static_key_enabled(&cpu_has_bear)) ? (nospec_uses_trampoline() || !static_key_enabled(&cpu_has_bear)) ?
"unexpected " : ""); "unexpected " : "");
return true;
}
} }
#ifdef CONFIG_PTDUMP_DEBUGFS #ifdef CONFIG_PTDUMP_DEBUGFS
......
...@@ -31,7 +31,7 @@ struct seq_file; ...@@ -31,7 +31,7 @@ struct seq_file;
void ptdump_walk_pgd_level(struct seq_file *m, struct mm_struct *mm); void ptdump_walk_pgd_level(struct seq_file *m, struct mm_struct *mm);
void ptdump_walk_pgd_level_debugfs(struct seq_file *m, struct mm_struct *mm, void ptdump_walk_pgd_level_debugfs(struct seq_file *m, struct mm_struct *mm,
bool user); bool user);
void ptdump_walk_pgd_level_checkwx(void); bool ptdump_walk_pgd_level_checkwx(void);
#define ptdump_check_wx ptdump_walk_pgd_level_checkwx #define ptdump_check_wx ptdump_walk_pgd_level_checkwx
void ptdump_walk_user_pgd_level_checkwx(void); void ptdump_walk_user_pgd_level_checkwx(void);
......
...@@ -362,9 +362,9 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, ...@@ -362,9 +362,9 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
} }
} }
static void ptdump_walk_pgd_level_core(struct seq_file *m, bool ptdump_walk_pgd_level_core(struct seq_file *m,
struct mm_struct *mm, pgd_t *pgd, struct mm_struct *mm, pgd_t *pgd,
bool checkwx, bool dmesg) bool checkwx, bool dmesg)
{ {
const struct ptdump_range ptdump_ranges[] = { const struct ptdump_range ptdump_ranges[] = {
#ifdef CONFIG_X86_64 #ifdef CONFIG_X86_64
...@@ -391,12 +391,17 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, ...@@ -391,12 +391,17 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m,
ptdump_walk_pgd(&st.ptdump, mm, pgd); ptdump_walk_pgd(&st.ptdump, mm, pgd);
if (!checkwx) if (!checkwx)
return; return true;
if (st.wx_pages) if (st.wx_pages) {
pr_info("x86/mm: Checked W+X mappings: FAILED, %lu W+X pages found.\n", pr_info("x86/mm: Checked W+X mappings: FAILED, %lu W+X pages found.\n",
st.wx_pages); st.wx_pages);
else
return false;
} else {
pr_info("x86/mm: Checked W+X mappings: passed, no W+X pages found.\n"); pr_info("x86/mm: Checked W+X mappings: passed, no W+X pages found.\n");
return true;
}
} }
void ptdump_walk_pgd_level(struct seq_file *m, struct mm_struct *mm) void ptdump_walk_pgd_level(struct seq_file *m, struct mm_struct *mm)
...@@ -431,12 +436,12 @@ void ptdump_walk_user_pgd_level_checkwx(void) ...@@ -431,12 +436,12 @@ void ptdump_walk_user_pgd_level_checkwx(void)
#endif #endif
} }
void ptdump_walk_pgd_level_checkwx(void) bool ptdump_walk_pgd_level_checkwx(void)
{ {
if (!(__supported_pte_mask & _PAGE_NX)) if (!(__supported_pte_mask & _PAGE_NX))
return; return true;
ptdump_walk_pgd_level_core(NULL, &init_mm, INIT_PGD, true, false); return ptdump_walk_pgd_level_core(NULL, &init_mm, INIT_PGD, true, false);
} }
static int __init pt_dump_init(void) static int __init pt_dump_init(void)
......
...@@ -18,8 +18,11 @@ struct ptdump_state { ...@@ -18,8 +18,11 @@ struct ptdump_state {
const struct ptdump_range *range; const struct ptdump_range *range;
}; };
bool ptdump_walk_pgd_level_core(struct seq_file *m,
struct mm_struct *mm, pgd_t *pgd,
bool checkwx, bool dmesg);
void ptdump_walk_pgd(struct ptdump_state *st, struct mm_struct *mm, pgd_t *pgd); void ptdump_walk_pgd(struct ptdump_state *st, struct mm_struct *mm, pgd_t *pgd);
void ptdump_check_wx(void); bool ptdump_check_wx(void);
static inline void debug_checkwx(void) static inline void debug_checkwx(void)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment