From: Wei-min Pan <weimin.pan@oracle.com>
To: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PING 2][PATCH PR gdb/21870] aarch64: Leftover uncleared debug registers
Date: Fri, 10 Nov 2017 01:07:00 -0000 [thread overview]
Message-ID: <7c25007d-00a1-0456-6f51-0e9a39427785@oracle.com> (raw)
In-Reply-To: <300a7ff5-11c4-ef89-907a-c82c08973f29@oracle.com>
On 10/20/2017 5:58 PM, Wei-min Pan wrote:
> On 10/6/2017 3:18 PM, Weimin Pan wrote:
>> Â Â Â Â The root cause is that ptrace() does not validate either
>> Â Â Â Â address or size when setting a hardware watchpoint/breakpoint.
>> Â Â Â Â As a result, watchpoints were set at address 0, the initial
>> value of
>> Â Â Â Â aarch64_debug_reg_state in aarch64_process_info, when the
>> Â Â Â Â PTRACE_SETREGSET request was first made in
>> Â Â Â Â aarch64_linux_set_debug_regs(), in preparation for resuming the
>> thread.
>>
>> Â Â Â Â Other than changing the kernel ptrace() implementation, first
>> attempt to
>> Â Â Â Â fix this problem in gdb was to focus on aarch64_linux_new_thread().
>> Â Â Â Â Instead of marking all hardware breakpoint/watchpoint register
>> pairs for
>> Â Â Â Â the new thread that have changed, tried to reflect the state by
>> using
>> Â Â Â Â either DR_MARK_ALL_CHANGED() if they have really been changed or
>> Â Â Â Â DR_CLEAR_CHANGED() otherwise. But finding whether or not the
>> registers
>> Â Â Â Â have been changed by using parent's lwp_info or
>> aarch64_process_info
>> Â Â Â Â proved to be hard or incorrect, especially the latter which caused
>> Â Â Â Â gdbserver to crash in the middle of the ptid_of_lwp() call.
>>
>> Â Â Â Â Another approach was then taken - add function
>> initial_control_length()
>> Â Â Â Â to validate the contents in the control registers, basing on the
>> fact that
>> Â Â Â Â the kernel only supports Byte Address Select (BAS) values of
>> 0x1, 0x3, 0xf
>> Â Â Â Â and 0xff, before calling ptrace() in
>> aarch64_linux_set_debug_regs().
>>
>> Â Â Â Â Tested on aarch64-linux-gnu. No regressions.
>> ---
>>  gdb/ChangeLog                   | 7 +++++++
>> Â gdb/nat/aarch64-linux-hw-point.c | 18 +++++++++++++++++-
>> Â 2 files changed, 24 insertions(+), 1 deletion(-)
>>
>> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
>> index c4f55a8137..543e1a0487 100644
>> --- a/gdb/ChangeLog
>> +++ b/gdb/ChangeLog
>> @@ -1,3 +1,10 @@
>> +2017-10-06 Weimin Pan <weimin.pan@oracle.com>
>> +
>> +Â Â Â PR gdb/21870
>> +Â Â Â * nat/aarch64-linux-hw-point.c (aarch64_linux_set_debug_regs):
>> +Â Â Â Call new function to validate the length in control registers.
>> +Â Â Â (initial_control_length): New function.
>> +
>>  2017-09-15 Pedro Alves <palves@redhat.com>
>> Â Â Â Â Â Â * compile/compile-c-types.c (convert_enum, convert_int)
>> diff --git a/gdb/nat/aarch64-linux-hw-point.c
>> b/gdb/nat/aarch64-linux-hw-point.c
>> index 9800d9a59c..22c0a48c14 100644
>> --- a/gdb/nat/aarch64-linux-hw-point.c
>> +++ b/gdb/nat/aarch64-linux-hw-point.c
>> @@ -548,6 +548,22 @@ aarch64_handle_watchpoint (enum
>> target_hw_bp_type type, CORE_ADDR addr,
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â state);
>> Â }
>> Â +/* Validate the lengths of breakpoints/watchpoints, according to the
>> +Â Â contents of these hardware debug control registers, and return
>> +  true if all these registers contain zero length. */
>> +
>> +static bool
>> +initial_control_length (const unsigned int *ctrl, int count)
>> +{
>> +Â for (int i = 0; i < count; i++)
>> +Â Â Â {
>> +Â Â Â Â Â if (DR_CONTROL_LENGTH (ctrl[i]))
>> +Â Â Â Â Â Â Â return false;
>> +Â Â Â }
>> +
>> +Â return true;
>> +}
>> +
>> Â /* Call ptrace to set the thread TID's hardware breakpoint/watchpoint
>>     registers with data from *STATE. */
>> Â @@ -566,7 +582,7 @@ aarch64_linux_set_debug_regs (const struct
>> aarch64_debug_reg_state *state,
>> Â Â Â count = watchpoint ? aarch64_num_wp_regs : aarch64_num_bp_regs;
>> Â Â Â addr = watchpoint ? state->dr_addr_wp : state->dr_addr_bp;
>> Â Â Â ctrl = watchpoint ? state->dr_ctrl_wp : state->dr_ctrl_bp;
>> -Â if (count == 0)
>> +Â if (count == 0 || initial_control_length (ctrl, count))
>> Â Â Â Â Â return;
>> Â Â Â iov.iov_len = (offsetof (struct user_hwdebug_state, dbg_regs)
>> Â Â Â Â Â Â Â Â Â Â + count * sizeof (regs.dbg_regs[0]));
>
prev parent reply other threads:[~2017-11-10 1:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1507328314-114545-1-git-send-email-weimin.pan@oracle.com>
2017-10-21 0:58 ` [PING][PATCH " Wei-min Pan
2017-10-22 21:15 ` Yao Qi
2017-10-23 16:38 ` Wei-min Pan
2017-10-27 9:05 ` Yao Qi
2017-10-28 0:20 ` Weimin Pan
2017-11-10 1:07 ` Wei-min Pan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7c25007d-00a1-0456-6f51-0e9a39427785@oracle.com \
--to=weimin.pan@oracle.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox