diff mbox series

[01/10] arm64: debug: Don't propagate UNKNOWN FAR into si_code for debug signals

Message ID 20190301132809.24653-2-will.deacon@arm.com (mailing list archive)
State New, archived
Headers show
Series Rework debug exception handling code | expand

Commit Message

Will Deacon March 1, 2019, 1:28 p.m. UTC
FAR_EL1 is UNKNOWN for all debug exceptions other than those caused by
taking a hardware watchpoint. Unfortunately, if a debug handler returns
a non-zero value, then we will propagate the UNKNOWN FAR value to
userspace via the si_addr field of the SIGTRAP siginfo_t.

Instead, let's set si_addr to take on the PC of the faulting instruction,
which we have available in the current pt_regs.

Cc: <stable@vger.kernel.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
 arch/arm64/mm/fault.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Mark Rutland March 1, 2019, 1:45 p.m. UTC | #1
On Fri, Mar 01, 2019 at 01:28:00PM +0000, Will Deacon wrote:
> FAR_EL1 is UNKNOWN for all debug exceptions other than those caused by
> taking a hardware watchpoint. Unfortunately, if a debug handler returns
> a non-zero value, then we will propagate the UNKNOWN FAR value to
> userspace via the si_addr field of the SIGTRAP siginfo_t.
> 
> Instead, let's set si_addr to take on the PC of the faulting instruction,
> which we have available in the current pt_regs.
> 
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Will Deacon <will.deacon@arm.com>

Reviewed-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> ---
>  arch/arm64/mm/fault.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
> index efb7b2cbead5..ef46925096f0 100644
> --- a/arch/arm64/mm/fault.c
> +++ b/arch/arm64/mm/fault.c
> @@ -824,11 +824,12 @@ void __init hook_debug_fault_code(int nr,
>  	debug_fault_info[nr].name	= name;
>  }
>  
> -asmlinkage int __exception do_debug_exception(unsigned long addr,
> +asmlinkage int __exception do_debug_exception(unsigned long addr_if_watchpoint,
>  					      unsigned int esr,
>  					      struct pt_regs *regs)
>  {
>  	const struct fault_info *inf = esr_to_debug_fault_info(esr);
> +	unsigned long pc = instruction_pointer(regs);
>  	int rv;
>  
>  	/*
> @@ -838,14 +839,14 @@ asmlinkage int __exception do_debug_exception(unsigned long addr,
>  	if (interrupts_enabled(regs))
>  		trace_hardirqs_off();
>  
> -	if (user_mode(regs) && !is_ttbr0_addr(instruction_pointer(regs)))
> +	if (user_mode(regs) && !is_ttbr0_addr(pc))
>  		arm64_apply_bp_hardening();
>  
> -	if (!inf->fn(addr, esr, regs)) {
> +	if (!inf->fn(addr_if_watchpoint, esr, regs)) {
>  		rv = 1;
>  	} else {
>  		arm64_notify_die(inf->name, regs,
> -				 inf->sig, inf->code, (void __user *)addr, esr);
> +				 inf->sig, inf->code, (void __user *)pc, esr);
>  		rv = 0;
>  	}
>  
> -- 
> 2.11.0
>
Sasha Levin March 5, 2019, 1:35 p.m. UTC | #2
Hi,

[This is an automated email]

This commit has been processed because it contains a -stable tag.
The stable tag indicates that it's relevant for the following trees: all

The bot has tested the following trees: v4.20.13, v4.19.26, v4.14.104, v4.9.161, v4.4.176, v3.18.136.

v4.20.13: Failed to apply! Possible dependencies:
    356607f21e60 ("kasan, arm64: fix up fault handling logic")

v4.19.26: Failed to apply! Possible dependencies:
    356607f21e60 ("kasan, arm64: fix up fault handling logic")
    359048f91db4 ("arm64/mm: Define esr_to_debug_fault_info()")
    6fa998e83ef9 ("signal/arm64: Push siginfo generation into arm64_notify_die")
    dbfe3828a6f3 ("arm64/mm: Reorganize arguments for is_el1_permission_fault()")

v4.14.104: Failed to apply! Possible dependencies:
    1fc5dce78ad1 ("arm64/sve: Low-level SVE architectural state manipulation functions")
    2923f5ea7738 ("nds32: Exception handling")
    2c9120f3a86a ("arm64: signal: Make force_signal_inject more robust")
    356607f21e60 ("kasan, arm64: fix up fault handling logic")
    359048f91db4 ("arm64/mm: Define esr_to_debug_fault_info()")
    3eb0f5193b49 ("signal: Ensure every siginfo we send has all bits initialized")
    3f7c86b2382e ("arm64: Update fault_info table with new exception types")
    42dbf54e8890 ("arm64: consistently log ESR and page table")
    526c3ddb6aa2 ("signal/arm64: Document conflicts with SI_USER and SIGFPE,SIGTRAP,SIGBUS")
    532826f3712b ("arm64: Mirror arm for unimplemented compat syscalls")
    6fa998e83ef9 ("signal/arm64: Push siginfo generation into arm64_notify_die")
    92ff0674f5d8 ("arm64: mm: Rework unhandled user pagefaults to call arm64_force_sig_info")
    94ef7ecbdf6f ("arm64: fpsimd: Correctly annotate exception helpers called from asm")
    969e61ba87f9 ("arm64: make is_permission_fault() name clearer")
    af40ff687bc9 ("arm64: signal: Ensure si_code is valid for all fault signals")
    bc0ee4760364 ("arm64/sve: Core task context handling")
    cc19846079a7 ("arm64: fault: Don't leak data in ESR context for user fault on kernel VA")
    dbfe3828a6f3 ("arm64/mm: Reorganize arguments for is_el1_permission_fault()")

v4.9.161: Failed to apply! Possible dependencies:
    0e3a9026396c ("arm64: mm: Update perf accounting to handle poison faults")
    1f9b8936f36f ("arm64: Decode information from ESR upon mem faults")
    32015c235603 ("arm64: exception: handle Synchronous External Abort")
    356607f21e60 ("kasan, arm64: fix up fault handling logic")
    359048f91db4 ("arm64/mm: Define esr_to_debug_fault_info()")
    3eb0f5193b49 ("signal: Ensure every siginfo we send has all bits initialized")
    532826f3712b ("arm64: Mirror arm for unimplemented compat syscalls")
    67ce16ec15ce ("arm64: mm: print out correct page table entries")
    6fa998e83ef9 ("signal/arm64: Push siginfo generation into arm64_notify_die")
    786889636ad7 ("arm64: Handle faults caused by inadvertent user access with PAN enabled")
    7edda0886bc3 ("acpi: apei: handle SEA notification type for ARMv8")
    83016b204225 ("arm64: mm: print file name of faulting vma")
    92ff0674f5d8 ("arm64: mm: Rework unhandled user pagefaults to call arm64_force_sig_info")
    969e61ba87f9 ("arm64: make is_permission_fault() name clearer")
    a8ada146f517 ("arm64: Update the synchronous external abort fault description")
    b824b9306823 ("arm64: print a fault message when attempting to write RO memory")
    c07ab957d9af ("arm64: Call __show_regs directly")
    cc19846079a7 ("arm64: fault: Don't leak data in ESR context for user fault on kernel VA")
    dbfe3828a6f3 ("arm64/mm: Reorganize arguments for is_el1_permission_fault()")
    e7c600f149b8 ("arm64: hwpoison: add VM_FAULT_HWPOISON[_LARGE] handling")

v4.4.176: Failed to apply! Possible dependencies:
    09a6adf53d42 ("arm64: mm: unaligned access by user-land should be received as SIGBUS")
    0a8ea52c3eb1 ("arm64: Add HAVE_REGS_AND_STACK_ACCESS_API feature")
    1f9b8936f36f ("arm64: Decode information from ESR upon mem faults")
    2dd0e8d2d2a1 ("arm64: Kprobes with single stepping support")
    32015c235603 ("arm64: exception: handle Synchronous External Abort")
    356607f21e60 ("kasan, arm64: fix up fault handling logic")
    359048f91db4 ("arm64/mm: Define esr_to_debug_fault_info()")
    57f4959bad0a ("arm64: kernel: Add support for User Access Override")
    6afedcd23cfd ("arm64: mm: Add trace_irqflags annotations to do_debug_exception()")
    7dd01aef0557 ("arm64: trap userspace "dc cvau" cache operation on errata-affected core")
    9dbd5bb25c56 ("arm64: Refactor sysinstr exception handling")
    a8ada146f517 ("arm64: Update the synchronous external abort fault description")
    bbb1681ee365 ("arm64: mm: mark fault_info table const")
    d5370f754875 ("arm64: prefetch: add alternative pattern for CPUs without a prefetcher")
    d59bee887231 ("arm64: Add more test functions to insn.c")
    e04a28d45ff3 ("arm64: debug: re-enable irqs before sending breakpoint SIGTRAP")
    e7227d0e528f ("arm64: Cleanup SCTLR flags")

v3.18.136: Failed to apply! Possible dependencies:
    09a6adf53d42 ("arm64: mm: unaligned access by user-land should be received as SIGBUS")
    2dd0e8d2d2a1 ("arm64: Kprobes with single stepping support")
    31dde116cb08 ("arm64: Replace set_arch_dma_coherent_ops with arch_setup_dma_ops")
    3505f30fb6a9 ("ARM64 / ACPI: If we chose to boot from acpi then disable FDT")
    359048f91db4 ("arm64/mm: Define esr_to_debug_fault_info()")
    37655163ce1a ("ARM64 / ACPI: Get RSDP and ACPI boot-time tables")
    587064b610c7 ("arm64: Add framework for legacy instruction emulation")
    6933de0ca0b7 ("ARM64 / ACPI: Select ACPI_REDUCED_HARDWARE_ONLY if ACPI is enabled on ARM64")
    7c59a3df15df ("ARM64 / ACPI: Get PSCI flags in FADT for PSCI init")
    86dca36e6ba0 ("arm64: use private ratelimit state along with show_unhandled_signals")
    876945dbf649 ("arm64: Hook up IOMMU dma_ops")
    9b79f52d1a70 ("arm64: Add support for hooks to handle undefined instructions")
    b10d79f76085 ("ARM64 / ACPI: Introduce early_param "acpi=" to enable/disable ACPI")
    b6197b93fa4b ("arm64 : Introduce support for ACPI _CCA object")
    bbb1681ee365 ("arm64: mm: mark fault_info table const")
    d8f4f161e31f ("ACPI: move arm64 GSI IRQ model to generic GSI IRQ layer")
    de7ee503f279 ("arm64: introduce is_device_dma_coherent")
    f871d2680707 ("arm64: Fix show_unhandled_signal_ratelimited usage")
    fbe61ec71ac9 ("ARM64 / ACPI: Introduce ACPI_IRQ_MODEL_GIC and register device's gsi")
    fccb9a81fd08 ("ARM64 / ACPI: Parse MADT for SMP initialization")


How should we proceed with this patch?

--
Thanks,
Sasha
diff mbox series

Patch

diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index efb7b2cbead5..ef46925096f0 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -824,11 +824,12 @@  void __init hook_debug_fault_code(int nr,
 	debug_fault_info[nr].name	= name;
 }
 
-asmlinkage int __exception do_debug_exception(unsigned long addr,
+asmlinkage int __exception do_debug_exception(unsigned long addr_if_watchpoint,
 					      unsigned int esr,
 					      struct pt_regs *regs)
 {
 	const struct fault_info *inf = esr_to_debug_fault_info(esr);
+	unsigned long pc = instruction_pointer(regs);
 	int rv;
 
 	/*
@@ -838,14 +839,14 @@  asmlinkage int __exception do_debug_exception(unsigned long addr,
 	if (interrupts_enabled(regs))
 		trace_hardirqs_off();
 
-	if (user_mode(regs) && !is_ttbr0_addr(instruction_pointer(regs)))
+	if (user_mode(regs) && !is_ttbr0_addr(pc))
 		arm64_apply_bp_hardening();
 
-	if (!inf->fn(addr, esr, regs)) {
+	if (!inf->fn(addr_if_watchpoint, esr, regs)) {
 		rv = 1;
 	} else {
 		arm64_notify_die(inf->name, regs,
-				 inf->sig, inf->code, (void __user *)addr, esr);
+				 inf->sig, inf->code, (void __user *)pc, esr);
 		rv = 0;
 	}