Skip to content

Commit d878efc

Browse files
joergroedelKAGA-KOKO
authored andcommitted
x86/mm/pti: Move user W+X check into pti_finalize()
The user page-table gets the updated kernel mappings in pti_finalize(), which runs after the RO+X permissions got applied to the kernel page-table in mark_readonly(). But with CONFIG_DEBUG_WX enabled, the user page-table is already checked in mark_readonly() for insecure mappings. This causes false-positive warnings, because the user page-table did not get the updated mappings yet. Move the W+X check for the user page-table into pti_finalize() after it updated all required mappings. [ tglx: Folded !NX supported fix ] Signed-off-by: Joerg Roedel <jroedel@suse.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: "H . Peter Anvin" <hpa@zytor.com> Cc: linux-mm@kvack.org Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Juergen Gross <jgross@suse.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Jiri Kosina <jkosina@suse.cz> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Brian Gerst <brgerst@gmail.com> Cc: David Laight <David.Laight@aculab.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: Eduardo Valentin <eduval@amazon.com> Cc: Greg KH <gregkh@linuxfoundation.org> Cc: Will Deacon <will.deacon@arm.com> Cc: aliguori@amazon.com Cc: daniel.gruss@iaik.tugraz.at Cc: hughd@google.com Cc: keescook@google.com Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Waiman Long <llong@redhat.com> Cc: Pavel Machek <pavel@ucw.cz> Cc: "David H . Gutteridge" <dhgutteridge@sympatico.ca> Cc: joro@8bytes.org Link: https://lkml.kernel.org/r/1533727000-9172-1-git-send-email-joro@8bytes.org
1 parent a29dba1 commit d878efc

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

arch/x86/include/asm/pgtable.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ int __init __early_make_pgtable(unsigned long address, pmdval_t pmd);
3030
void ptdump_walk_pgd_level(struct seq_file *m, pgd_t *pgd);
3131
void ptdump_walk_pgd_level_debugfs(struct seq_file *m, pgd_t *pgd, bool user);
3232
void ptdump_walk_pgd_level_checkwx(void);
33+
void ptdump_walk_user_pgd_level_checkwx(void);
3334

3435
#ifdef CONFIG_DEBUG_WX
35-
#define debug_checkwx() ptdump_walk_pgd_level_checkwx()
36+
#define debug_checkwx() ptdump_walk_pgd_level_checkwx()
37+
#define debug_checkwx_user() ptdump_walk_user_pgd_level_checkwx()
3638
#else
37-
#define debug_checkwx() do { } while (0)
39+
#define debug_checkwx() do { } while (0)
40+
#define debug_checkwx_user() do { } while (0)
3841
#endif
3942

4043
/*

arch/x86/mm/dump_pagetables.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,12 +569,13 @@ void ptdump_walk_pgd_level_debugfs(struct seq_file *m, pgd_t *pgd, bool user)
569569
}
570570
EXPORT_SYMBOL_GPL(ptdump_walk_pgd_level_debugfs);
571571

572-
static void ptdump_walk_user_pgd_level_checkwx(void)
572+
void ptdump_walk_user_pgd_level_checkwx(void)
573573
{
574574
#ifdef CONFIG_PAGE_TABLE_ISOLATION
575575
pgd_t *pgd = INIT_PGD;
576576

577-
if (!static_cpu_has(X86_FEATURE_PTI))
577+
if (!(__supported_pte_mask & _PAGE_NX) ||
578+
!static_cpu_has(X86_FEATURE_PTI))
578579
return;
579580

580581
pr_info("x86/mm: Checking user space page tables\n");
@@ -586,7 +587,6 @@ static void ptdump_walk_user_pgd_level_checkwx(void)
586587
void ptdump_walk_pgd_level_checkwx(void)
587588
{
588589
ptdump_walk_pgd_level_core(NULL, NULL, true, false);
589-
ptdump_walk_user_pgd_level_checkwx();
590590
}
591591

592592
static int __init pt_dump_init(void)

arch/x86/mm/pti.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,4 +646,6 @@ void pti_finalize(void)
646646
*/
647647
pti_clone_entry_text();
648648
pti_clone_kernel_text();
649+
650+
debug_checkwx_user();
649651
}

0 commit comments

Comments
 (0)