RFC: ARM: breakpoint: CFI breakpoints only on demand
Subsystems (3)
PATCH v2 1/1 RFC: ARM: breakpoint: CFI breakpoints only on demand
This removes the stub hw_breakpoint_cfi_handler() from ARM, making it not steal breakpoint type 0x03 (ARM_ENTRY_CFI_BREAKPOINT) unless CFI is actively used in the kernel.
When not instrumenting with CFI, we fall through to return 1 from hw_breakpoint_pending() "unhandled fault" so userspace can make use of this breakpoint.
This of course does not work if userspace want to use CFI and custom breakpoints at the same time, and CONFIG_CFI does exist as something users might want to select for their kernel. If this is not good acceptable we need to think about other ways for CFI to interfer, such as not using BKPT at all (rather something like BUG()) and back out the offending patch until the compiler behaviour has changed.
---
Trying to solve the CFI bug. Let's see of this first
approach is acceptable for the reporter.
---
Changes in v2:
- Resending as non-RFC so it can be applied as a band-aid.
- Link to v1: https://patch.msgid.link/[email protected]
--- arch/arm/kernel/hw_breakpoint.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
arch/arm/kernel/hw_breakpoint.c +2 -4
@@ -929,10 +929,6 @@ static void hw_breakpoint_cfi_handler(struct pt_regs *regs) break; } } -#else -static void hw_breakpoint_cfi_handler (struct pt_regs *regs) -{ -}#endif /*
@@ -964,9 +960,11 @@ static int hw_breakpoint_pending(unsigned long addr, unsigned int fsr,case ARM_ENTRY_SYNC_WATCHPOINT :watchpoint_handler (addr, fsr, regs);break ; +#ifdef CONFIG_CFI case ARM_ENTRY_CFI_BREAKPOINT :hw_breakpoint_cfi_handler (regs);break ; +#endif default : ret =1 ;/* Unhandled fault. */ }
---
base-commit: 8cd9520d35a6c38db6567e97dd93b1f11f185dc6
change-id: 20260626-arm32-cfi-bug-10fb960749c4
Best regards,
Signature · 1 line
Linus Walleij <[email protected]>
Quoted 3 lines · Linus Walleij
This removes the stub
hw_breakpoint_cfi_handler()from ARM, making it not steal breakpoint type0x03(ARM_ENTRY_CFI_BREAKPOINT) unless CFI is actively used in the kernel.
Was meaning to send a non-RFC of this band-aid patch, but missed to strip off "RFC", mea culpa.
Yours,
Linus Walleij
Mark Rutland
maintainerQuoted 11 lines · Linus Walleij
This removes the stub
hw_breakpoint_cfi_handler()from ARM, making it not steal breakpoint type0x03(ARM_ENTRY_CFI_BREAKPOINT) unless CFI is actively used in the kernel.When not instrumenting with CFI, we fall through to return 1 from
hw_breakpoint_pending()"unhandled fault" so userspace can make use of this breakpoint.This of course does not work if userspace want to use CFI and custom breakpoints at the same time, and
CONFIG_CFIdoes exist as something users might want to select for their kernel.
I don't follow this part. CONFIG_CFI is for the kernel; it has nothing to do with what userspace wnats to do.
AFAICT, when the kernel is built with CONFIG_CFI, if userspace uses BKPT at all, for any reason, it can cause the kernel to die().
Quoted 4 lines
If this is not good acceptable we need to think about other ways for CFI to interfer, such as not using BKPT at all (rather something like
BUG()) and back out the offending patch until the compiler behaviour has changed.
See comments below.
Quoted 31 lines
Fixes c3f89986fde7 ("ARM: 9391/2: hw_breakpoint: Handle CFI breakpoints")Reported-by slipher <[email protected]>Closes https://lore.kernel.org/lkml/kJqktbpLphg_Pk5I5SPptgTLjl3E3eq5mN5UzCslyFj7Q1Irp-wDid4mj5eQVd2iZtRGXgeZd8goq195EkXdjyt864YMc8mVb2B9NGH91NQ=@protonmail.com/ open hereSigned-off-by Linus Walleij <[email protected]>---
Trying to solve the CFI bug. Let's see of this first
approach is acceptable for the reporter.
---
Changes in v2:
- Resending as non-RFC so it can be applied as a band-aid.
- Link to v1: https://patch.msgid.link/[email protected]--- arch/arm/kernel/hw_breakpoint.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)arch/arm/kernel/hw_breakpoint.c +0
-4@@ -929,10 +929,6 @@ static void hw_breakpoint_cfi_handler(struct pt_regs *regs) break; } } -#else -static void hw_breakpoint_cfi_handler (struct pt_regs *regs) -{ -}#endif /*
arch/arm/kernel/hw_breakpoint.c static int hw_breakpoint_pending(unsigned long addr, unsigned int fsr, · line 967
Quoted 8 lines
arch/arm/kernel/hw_breakpoint.c +2
-0@@ -964,9 +960,11 @@ static int hw_breakpoint_pending(unsigned long addr, unsigned int fsr,case ARM_ENTRY_SYNC_WATCHPOINT :watchpoint_handler (addr, fsr, regs);break ; +#ifdef CONFIG_CFI case ARM_ENTRY_CFI_BREAKPOINT :hw_breakpoint_cfi_handler (regs);break ; +#endif
AFAICT, hw_breakpoint_cfi_handler() is only intended to handle BKPT instructions executed in kernel mode, and even when the kernel is build with CF support, it doesn't make sense to call that for BKPT instructions executed in user mode.
On arm64, we have separate paths for BRK exceptions from user mode (do_el0_brk64()) and kernel mode (do_el1_brk64()).
Surely you can check kernel_mode(regs) or user_mode(regs) to distinguish the two cases, and only call hw_breakpoint_cfi_handler() when the exception was taken from kernel mode?
Mark.
Quoted 13 lines
arch/arm/kernel/hw_breakpoint.c +0
-1default : ret =1 ;/* Unhandled fault. */ } ---base-commit:
8cd9520d35a6c38db6567e97dd93b1f11f185dc6
change-id: 20260626-arm32-cfi-bug-10fb960749c4Best regards,
Signature · 1 line
Linus Walleij <[email protected]>
Quoted 11 lines · Mark Rutland
AFAICT,
hw_breakpoint_cfi_handler()is only intended to handle BKPT instructions executed in kernel mode, and even when the kernel is build with CF support, it doesn't make sense to call that for BKPT instructions executed in user mode.On arm64, we have separate paths for BRK exceptions from user mode (
do_el0_brk64()) and kernel mode (do_el1_brk64()).Surely you can check
kernel_mode(regs)oruser_mode(regs)to distinguish the two cases, and only callhw_breakpoint_cfi_handler()when the exception was taken from kernel mode?
You're right of course... I'll add a check like that and see if this solves the problem for the reporter.
Yours,
Linus Walleij