Commit cdc27c27 authored by Will Deacon's avatar Will Deacon Committed by Catalin Marinas

arm64: ptrace: avoid using HW_BREAKPOINT_EMPTY for disabled events

Commit 8f34a1da ("arm64: ptrace: use HW_BREAKPOINT_EMPTY type for
disabled breakpoints") fixed an issue with GDB trying to zero breakpoint
control registers. The problem there is that the arch hw_breakpoint code
will attempt to create a (disabled), execute breakpoint of length 0.

This will fail validation and report unexpected failure to GDB. To avoid
this, we treated disabled breakpoints as HW_BREAKPOINT_EMPTY, but that
seems to have broken with recent kernels, causing watchpoints to be
treated as TYPE_INST in the core code and returning ENOSPC for any
further breakpoints.

This patch fixes the problem by prioritising the `enable' field of the
breakpoint: if it is cleared, we simply update the perf_event_attr to
indicate that the thing is disabled and don't bother changing either the
type or the length. This reinforces the behaviour that the breakpoint
control register is essentially read-only apart from the enable bit
when disabling a breakpoint.

Cc: <stable@vger.kernel.org>
Reported-by: default avatarAaron Liu <liucy214@gmail.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
parent 319e2e3f
...@@ -214,10 +214,10 @@ static int ptrace_hbp_fill_attr_ctrl(unsigned int note_type, ...@@ -214,10 +214,10 @@ static int ptrace_hbp_fill_attr_ctrl(unsigned int note_type,
{ {
int err, len, type, disabled = !ctrl.enabled; int err, len, type, disabled = !ctrl.enabled;
if (disabled) { attr->disabled = disabled;
len = 0; if (disabled)
type = HW_BREAKPOINT_EMPTY; return 0;
} else {
err = arch_bp_generic_fields(ctrl, &len, &type); err = arch_bp_generic_fields(ctrl, &len, &type);
if (err) if (err)
return err; return err;
...@@ -234,11 +234,9 @@ static int ptrace_hbp_fill_attr_ctrl(unsigned int note_type, ...@@ -234,11 +234,9 @@ static int ptrace_hbp_fill_attr_ctrl(unsigned int note_type,
default: default:
return -EINVAL; return -EINVAL;
} }
}
attr->bp_len = len; attr->bp_len = len;
attr->bp_type = type; attr->bp_type = type;
attr->disabled = disabled;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment