Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: "Rohr, Stephan" <stephan.rohr@intel.com>
Cc: Tom Tromey <tom@tromey.com>,
	 "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
	 "guinevere@redhat.com" <guinevere@redhat.com>
Subject: Re: [PATCH vv2 1/1] gdb: fix assert after register write failure
Date: Wed, 21 Oct 2026 11:22:40 -0600	[thread overview]
Message-ID: <87zew7x927.fsf@tromey.com> (raw)
In-Reply-To: <DS7PR11MB624727248C6E3270C9E50E3C93662@DS7PR11MB6247.namprd11.prod.outlook.com> (Stephan Rohr's message of "Wed, 21 Oct 2026 13:47:56 +0000")

>>>>> Rohr, Stephan <stephan.rohr@intel.com> writes:

> m_register_status is never reset in regcache.c itself.  The bug is exposed in
> regcache::raw_write:

>   2. If the remote connection dies in "target_store_registers", the regcache is
>       deleted.  This deletes the register buffers and the register status buffer.

> I was able to manually reproduce the bug:

Thanks.  I reproduced it locally with your instructions.

I think the problem here is in step 2 -- the invalidator is accessing
'this' but this object has been destroyed.  That is, I set a breakpoint
where the invalidator is made and:

(top-gdb) p this
$1 = (regcache * const) 0x2f8f4d0

and then I set a breakpoint in ~regcache and "next"d over the call to
target_store_registers:

(top-gdb) break regcache::~regcache
Breakpoint 4 at 0xb9e722: regcache::~regcache. (2 locations)
(top-gdb) n
Thread 1 "gdb" hit Breakpoint 4.2, regcache::~regcache (this=0x2f8f4d0) at ../../binutils-gdb/gdb/regcache.h:370

... with the backtrace looking like:

(top-gdb) bt
#0  regcache::~regcache (this=0x2f8f4d0) at ../../binutils-gdb/gdb/regcache.h:370
[... lots of stuff ...]
#32 0x0000000000d75522 in target_store_registers (regcache=0x2f8f4d0, regno=0) at ../../binutils-gdb/gdb/target.c:3935
#33 0x0000000000b9818e in regcache::raw_write (this=0x2f8f4d0, regnum=0, src=...) at ../../binutils-gdb/gdb/regcache.c:889

I think what this means is that the invalidator here has a
use-after-free.  So I tend to think your patch also does this, and it
would be exposed by an ASAN build.

> An alternative for the nullptr check could be implemented by moving
> the call of "target_store_registers ()" into a try block and invalidate
> in "catch" if the error is not a "TARGET_CLOSE_ERROR".

> Does this sound reasonable?

I think so.  The key thing is that if 'this' is destroyed by the
operation, then it cannot be used again.  If TARGET_CLOSE_ERROR is the
only such case then that's fine.  It's possible the problem lies
elsewhere, I'm afraid I am not really certain.

thanks,
Tom

      reply	other threads:[~2026-10-21 17:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 14:11 [PATCH v2 0/1] " Stephan Rohr
2026-10-15 14:11 ` [PATCH vv2 1/1] " Stephan Rohr
2026-10-19 16:19   ` Tom Tromey
2026-10-21 13:47     ` Rohr, Stephan
2026-10-21 17:22       ` Tom Tromey [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=87zew7x927.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    --cc=guinevere@redhat.com \
    --cc=stephan.rohr@intel.com \
    /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