Skip to content

Commit

Permalink
x86/mm: Use lookup_address_in_pgd_attr() in show_fault_oops()
Browse files Browse the repository at this point in the history
Fix show_fault_oops() to not only look at the leaf PTE for detecting
NX violations, but to use the effective NX value returned by
lookup_address_in_pgd_attr() instead.

Signed-off-by: Juergen Gross <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
jgross1 authored and Ingo Molnar committed Apr 14, 2024
1 parent ceb647b commit d29dc51
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions arch/x86/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,18 +514,19 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code, unsigned long ad

if (error_code & X86_PF_INSTR) {
unsigned int level;
bool nx, rw;
pgd_t *pgd;
pte_t *pte;

pgd = __va(read_cr3_pa());
pgd += pgd_index(address);

pte = lookup_address_in_pgd(pgd, address, &level);
pte = lookup_address_in_pgd_attr(pgd, address, &level, &nx, &rw);

if (pte && pte_present(*pte) && !pte_exec(*pte))
if (pte && pte_present(*pte) && (!pte_exec(*pte) || nx))
pr_crit("kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n",
from_kuid(&init_user_ns, current_uid()));
if (pte && pte_present(*pte) && pte_exec(*pte) &&
if (pte && pte_present(*pte) && pte_exec(*pte) && !nx &&
(pgd_flags(*pgd) & _PAGE_USER) &&
(__read_cr4() & X86_CR4_SMEP))
pr_crit("unable to execute userspace code (SMEP?) (uid: %d)\n",
Expand Down

0 comments on commit d29dc51

Please sign in to comment.