[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250827014113.5852-4-b10902118@ntu.edu.tw>
Date: Wed, 27 Aug 2025 09:41:13 +0800
From: Bill Tsui <b10902118@....edu.tw>
To: oleg@...hat.com,
linux@...linux.org.uk,
catalin.marinas@....com,
will@...nel.org
Cc: linux-arm-kernel@...ts.infradead.org,
linux-kernel@...r.kernel.org,
Bill Tsui <b10902118@....edu.tw>
Subject: [PATCH v2 3/3] ARM: ptrace: minimize default bp_len for hw breakpoints to pass check
PTRACE_SETHBPREGS fails when setting a hardware breakpoint on a
non-4-byte aligned address with a valid length to a 32-bit tracee. The
length should be valid as long as the range started from the address
is within one aligned 4 bytes.
The cause is that ptrace_sethbpregs() can only modify either
addr or ctrl of a breakpoint per call, but always checks alignment in
hw_breakpoint_arch_parse(). If a breakpoint has ctrl.len=4 (the
default), then users cannot set the addr to a non-4-byte aligned
address. Likewise, if the addr was previously set unaligned, users
cannot set ctrl.len to 4.
This patch mitigates the issue by minimizing the default bp_len, so
that any possibly valid address can pass the check with it. However, it
does not solve misaligned addr/len in modifying existing breakpoints;
further work may be needed to remove or relax the alignment check.
Signed-off-by: Bill Tsui <b10902118@....edu.tw>
---
arch/arm/kernel/ptrace.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
index 7951b2c06..920cf77d1 100644
--- a/arch/arm/kernel/ptrace.c
+++ b/arch/arm/kernel/ptrace.c
@@ -415,12 +415,26 @@ static u32 ptrace_get_hbp_resource_info(void)
static struct perf_event *ptrace_hbp_create(struct task_struct *tsk, int type)
{
struct perf_event_attr attr;
+ int min_len;
+
+ /*
+ * min_len ensures any possibly valid address can pass alignment
+ * validation with it.
+ * In PTRACE_SETHBPREGS, addr and ctrl can only be set one after one. If
+ * addr is set first, ctrl will remain as initial value.
+ */
+ if (type == HW_BREAKPOINT_X)
+ min_len = (tsk && is_compat_thread(task_thread_info(tsk))) ?
+ HW_BREAKPOINT_LEN_2 :
+ HW_BREAKPOINT_LEN_4;
+ else // watchpoint
+ min_len = HW_BREAKPOINT_LEN_1;
ptrace_breakpoint_init(&attr);
/* Initialise fields to sane defaults. */
attr.bp_addr = 0;
- attr.bp_len = HW_BREAKPOINT_LEN_4;
+ attr.bp_len = min_len;
attr.bp_type = type;
attr.disabled = 1;
--
2.50.1
Powered by blists - more mailing lists