Skip to content

Commit 04a9f77

Browse files
kristina-martsenkoctmarinas
authored andcommitted
arm64: mm: Handle PAN faults on uaccess CPY* instructions
A subsequent patch will use CPY* instructions to copy between user and kernel memory. Add handling for PAN faults caused by an intended kernel memory access erroneously accessing user memory, in order to make it easier to debug kernel bugs and to keep the same behavior as with regular loads/stores. Signed-off-by: Kristina Martšenko <kristina.martsenko@arm.com> Reviewed-by: Robin Murphy <robin.murphy@arm.com> Link: https://lore.kernel.org/r/20250228170006.390100-3-kristina.martsenko@arm.com [catalin.marinas@arm.com: Folded the extable search into insn_may_access_user()] Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 653884f commit 04a9f77

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

arch/arm64/include/asm/extable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ do { \
3333
(b)->data = (tmp).data; \
3434
} while (0)
3535

36+
bool insn_may_access_user(unsigned long addr, unsigned long esr);
37+
3638
#ifdef CONFIG_BPF_JIT
3739
bool ex_handler_bpf(const struct exception_table_entry *ex,
3840
struct pt_regs *regs);

arch/arm64/mm/extable.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ static bool cpy_faulted_on_uaccess(const struct exception_table_entry *ex,
2020
return uaccess_is_write == fault_on_write;
2121
}
2222

23+
bool insn_may_access_user(unsigned long addr, unsigned long esr)
24+
{
25+
const struct exception_table_entry *ex = search_exception_tables(addr);
26+
27+
if (!ex)
28+
return false;
29+
30+
switch (ex->type) {
31+
case EX_TYPE_UACCESS_CPY:
32+
return cpy_faulted_on_uaccess(ex, esr);
33+
default:
34+
return true;
35+
}
36+
}
37+
2338
static inline unsigned long
2439
get_ex_fixup(const struct exception_table_entry *ex)
2540
{

arch/arm64/mm/fault.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr,
606606
die_kernel_fault("execution of user memory",
607607
addr, esr, regs);
608608

609-
if (!search_exception_tables(regs->pc))
609+
if (!insn_may_access_user(regs->pc, esr))
610610
die_kernel_fault("access to user memory outside uaccess routines",
611611
addr, esr, regs);
612612
}

0 commit comments

Comments
 (0)