Skip to content

Commit 8f34a1d

Browse files
wildea01ctmarinas
authored andcommitted
arm64: ptrace: use HW_BREAKPOINT_EMPTY type for disabled breakpoints
If a debugger tries to zero a hardware debug control register, the kernel will try to infer both the type and length of the breakpoint in order to sanity-check against the requested regset type. This will fail because the encoding will appear as a zero-length breakpoint. This patch changes the control register setting so that disabled breakpoints are treated as HW_BREAKPOINT_EMPTY and no further sanity-checking is required. Signed-off-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 7797d17 commit 8f34a1d

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

arch/arm64/kernel/ptrace.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,28 +234,33 @@ static int ptrace_hbp_fill_attr_ctrl(unsigned int note_type,
234234
struct arch_hw_breakpoint_ctrl ctrl,
235235
struct perf_event_attr *attr)
236236
{
237-
int err, len, type;
237+
int err, len, type, disabled = !ctrl.enabled;
238238

239-
err = arch_bp_generic_fields(ctrl, &len, &type);
240-
if (err)
241-
return err;
242-
243-
switch (note_type) {
244-
case NT_ARM_HW_BREAK:
245-
if ((type & HW_BREAKPOINT_X) != type)
246-
return -EINVAL;
247-
break;
248-
case NT_ARM_HW_WATCH:
249-
if ((type & HW_BREAKPOINT_RW) != type)
239+
if (disabled) {
240+
len = 0;
241+
type = HW_BREAKPOINT_EMPTY;
242+
} else {
243+
err = arch_bp_generic_fields(ctrl, &len, &type);
244+
if (err)
245+
return err;
246+
247+
switch (note_type) {
248+
case NT_ARM_HW_BREAK:
249+
if ((type & HW_BREAKPOINT_X) != type)
250+
return -EINVAL;
251+
break;
252+
case NT_ARM_HW_WATCH:
253+
if ((type & HW_BREAKPOINT_RW) != type)
254+
return -EINVAL;
255+
break;
256+
default:
250257
return -EINVAL;
251-
break;
252-
default:
253-
return -EINVAL;
258+
}
254259
}
255260

256261
attr->bp_len = len;
257262
attr->bp_type = type;
258-
attr->disabled = !ctrl.enabled;
263+
attr->disabled = disabled;
259264

260265
return 0;
261266
}

0 commit comments

Comments
 (0)