From: Andrew Burgess <aburgess@redhat.com>
To: YuPeng <yupeng@kylinos.cn>, gdb-patches@sourceware.org
Cc: tromey@sourceware.org, debianyu@163.com
Subject: Re: [PATCH] Fix use-after-free when Python Breakpoint.stop method deletes the breakpoint
Date: Thu, 19 Nov 2026 16:22:38 +0000 [thread overview]
Message-ID: <xhuyf8q2oiyep.fsf@aburgess-thinkpadp1gen8.rmtgb.csb> (raw)
In-Reply-To: <1794998055185602167.295606@kylinos.cn>
YuPeng <yupeng@kylinos.cn> writes:
> If a Python Breakpoint.stop method calls self.delete(), the underlying
> breakpoint is freed while bpstat is still processing it.
>
> delete_breakpoint tries to clear references with
> bpstat_remove_bp_location, but that only walks
> thread->control.stop_bpstat, which still points at the bpstat chain from
> the previous stop (it is cleared in proceed()), not the chain currently
> being built by bpstat_stop_status. The current chain therefore keeps a
> dangling breakpoint pointer, and gdb crashes on the next access.
>
> The reproducer from the bug report returns False from stop(), so the
> crash happens right after the callback while infrun examines the bpstat
> chain (the report shows bpstat_explains_signal).
>
> Fix:
> - Assign thread->control.stop_bpstat = bs_head before the check_status
> loop in bpstat_stop_status, so bpstat_remove_bp_location can find and
> nullify the reference in the chain being processed.
> - In bpstat_check_breakpoint_conditions, return early if
> bs->breakpoint_at became NULL after the extension language callback.
> - In bpstat_stop_status, re-read b = bs->breakpoint_at after
> bpstat_check_breakpoint_conditions and skip the entry if it is NULL.
>
> Tested on x86_64-linux with an ASan build: without the fix gdb aborts
> with a heap-use-after-free; with it the breakpoint is deleted and the
> inferior exits normally.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34379
>
> I do not have an FSF copyright assignment on file; please let me know
> if you think this change needs one.
> ---
> gdb/breakpoint.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
This will for sure need a test adding to the testsuite. You could look
at gdb.python/py-breakpoint*.exp for inspiration.
>
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index a23f5998..37be75e4 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -5988,6 +5988,10 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread)
> implemented. */
> bs->stop = breakpoint_ext_lang_cond_says_stop (b);
>
> + /* The callback may have deleted the breakpoint. */
> + if (bs->breakpoint_at == NULL)
GDB style uses nullptr not NULL.
Thanks,
Andrew
next prev parent reply other threads:[~2026-11-19 16:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 10:34 YuPeng
2026-11-18 14:26 ` Eli Zaretskii
2026-11-19 16:22 ` Andrew Burgess [this message]
2026-11-24 2:54 ` [PATCH v2] " YuPeng
2026-11-24 11:26 ` Andrew Burgess
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=xhuyf8q2oiyep.fsf@aburgess-thinkpadp1gen8.rmtgb.csb \
--to=aburgess@redhat.com \
--cc=debianyu@163.com \
--cc=gdb-patches@sourceware.org \
--cc=tromey@sourceware.org \
--cc=yupeng@kylinos.cn \
/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