From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id vYYxJ1d//Wrk7RsAWB0awg (envelope-from ) for ; Wed, 18 Nov 2026 05:35:03 -0500 Received: by simark.ca (Postfix, from userid 112) id 4BF991E087; Wed, 18 Nov 2026 05:35:03 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id A1CCE1E087 for ; Wed, 18 Nov 2026 05:35:00 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 442B14BA2E38 for ; Wed, 18 Nov 2026 10:34:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 442B14BA2E38 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by sourceware.org (Postfix) with ESMTPS id D71144BA2E33; Wed, 18 Nov 2026 10:34:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D71144BA2E33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kylinos.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D71144BA2E33 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794998065; cv=none; b=rwn99YWX98KqORZgyg/OMihPPYOjtPy1i7s+xy3MjRCjP9vrKXddOVFYvt9Ws0tA19czxZvMMSR35NJVEbo5VA3fST+a/J59P1Q5YMoZBkYCXDEjGwBYupRnAuEvV4PmG8hIADtAMnRX0fGQsrKvVBn5+fXrS2y+CjMUtlpGlqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794998065; c=relaxed/simple; bh=BRflYqOgLmGi6pUPbTViU05BD7xHLbBrEg5mHSuGjAM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=OqPEA6f6Kzi32QfWrxaJLMbxObBIxNinKxJY02S+FgL6RJ8ykXCSkuKKznq9l/xMnWDzb005rgUg6k7DaAWUFpNDb/GtmMY3PUi/VvH+sD3n70Yjfn6UvE8b2+dVu4s4YBlS5XCkJgt5FbK2Kmj5/F4oGUR8jJcEtmeYDeWJ2YI= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D71144BA2E33 X-UUID: 9b670af4e33b11f19a56ed5b684f684d-20261118 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.19, REQID:a6713f17-73e7-467a-b26f-02da7e0e237a, IP:0, U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:7db8b62, CLOUDID:f3826c9e8b74e848e045d25a8ebb4f30, BulkI D:nil,BulkQuantity:0,SF:102|865|898,TC:nil,Content:0|15|50|99,EDM:-3,IP:ni l,URL:99|1,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0, LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULS X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 9b670af4e33b11f19a56ed5b684f684d-20261118 X-User: yupeng@kylinos.cn Received: from send-mail.7o3lfd [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 811850997; Wed, 18 Nov 2026 18:34:17 +0800 From: YuPeng To: gdb-patches@sourceware.org Cc: tromey@sourceware.org,debianyu@163.com Subject: [PATCH] Fix use-after-free when Python Breakpoint.stop method deletes the breakpoint Date: Wed, 18 Nov 2026 18:34:15 +0800 Message-ID: <1794998055185602167.295606@kylinos.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org 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(+) 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) + return; + if (is_watchpoint (b)) { watchpoint *w = gdb::checked_static_cast (b); @@ -6231,6 +6235,10 @@ bpstat_stop_status (const address_space *aspace, removed_any = 0; + /* Let delete_breakpoint see the chain being built, so that it can + clear references to a breakpoint deleted by a callback. */ + thread->control.stop_bpstat = bs_head; + for (bs = bs_head; bs != NULL; bs = bs->next) { if (!bs->stop) @@ -6242,6 +6250,12 @@ bpstat_stop_status (const address_space *aspace, { bpstat_check_breakpoint_conditions (bs, thread); + /* Skip if the callback deleted the breakpoint, otherwise + re-read it. */ + if (bs->breakpoint_at == NULL) + continue; + b = bs->breakpoint_at; + if (bs->stop) { ++(b->hit_count); base-commit: bd92f21ae14b14aa135fb94919a92f2cdf66b2a4 -- 2.39.5