From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 14l7Lbl0BWthMTIAWB0awg (envelope-from ) for ; Tue, 24 Nov 2026 06:27:53 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=KH7NNFfY; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id A83A91E09B; Tue, 24 Nov 2026 06:27:53 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED 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 B1A0E1E09B for ; Tue, 24 Nov 2026 06:27:52 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9F927444D839 for ; Tue, 24 Nov 2026 11:27:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F927444D839 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=KH7NNFfY Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id F36ED445357D for ; Tue, 24 Nov 2026 11:26:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F36ED445357D Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F36ED445357D Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795519617; cv=none; b=NjcENPD2w8WN5cVIFLFztwuHiUgk2eOna00QJk2VTl+l/izD0Q/rzHAOr6+TDHTxo1wzJ3dSKzse9h7WTJeyTHUoX7Lguj+gxkCnLWfVUMr+dXBqIscewLXLzcuYj2R4DQ4R26+r5PANHsWtzkLhoYImmmtwMB0c7GFKron/ICw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795519617; c=relaxed/simple; bh=dtEobi2cogoa0yYe7bfMHy55S0rj5Cu1F3oFHpowjcg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=NE6Eh7VMXcUuyc2pqk6RjqK6ENFLig8/mHqTCX0dWsdusNhvCmYzY5YM5vjXNufyJDCsY0RPlz1YWsYmsXD3c1hfjWxNVTRAi00+onP1PDBH7CcIJCutXdu+Z/kqCHigYlmsD8Rbd1dUc7oB+trsunUhn+DSU3b/h2aORdiqnMQ= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=KH7NNFfY DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F36ED445357D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795519616; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zoEv75rAvW6tKs7//dMhrP3lFOh4PhUPVHke1aRKWgs=; b=KH7NNFfYBLBDR+eARzVbK4p8xVTipx5OCiNi0rCwiSnrHd3zm5iS2rpuVw5hSm7GZCVg5X Dd4dprx/A6S9YoZea6G71ggjkj2nw6MedZ4YZHmrn+t7xMo9TEocRgBKOIHFyKQp5WPbLo MM9gC/xIYMYZGkv1g832t4Ai30Jb0is= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-182-dXwqPRruN_agqA-e05iNZg-1; Tue, 24 Nov 2026 11:26:53 +0000 X-MC-Unique: dXwqPRruN_agqA-e05iNZg-1 X-Mimecast-MFC-AGG-ID: dXwqPRruN_agqA-e05iNZg_1795519612 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-490d2ac331bso3856340f8f.0 for ; Tue, 24 Nov 2026 03:26:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795519612; x=1796124412; h=content-type:mime-version:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=zoEv75rAvW6tKs7//dMhrP3lFOh4PhUPVHke1aRKWgs=; b=PtjN/BbUAVXBfXfYwKN0moNPCxFpF78wSSsysgAKlpVe04lhJ1HpwkN6hZZrCtJGys ma7h7TiltXz2xvYrzyCIlhHRU3L8k7Y25wxO6kJKTBntEgIzjGnROeSZctwPPLM1sgR3 VudQOcrw6gqeNX967X2WaR9yhdU73YWh6RrQxRd6KM7e2hsF/jAq08V8n/5CrDvORJei Kx1yjcihlQseZKgvOrZZ2vbZsy9YUA9DOtaInNVNlRDAic9RqL2XyksmE1Qjmr85I0TW PAwFAJeR4iuRSvp6EX7xO9/H5w4OTyn+ViHZmA2iAIPt9dBBagL5ufxFvcwhMXdGRWSf 4FCA== X-Forwarded-Encrypted: i=1; AL+hErHIcJYlEhZ2fa59DiD29dpkDXlOx5Oloda89VUlWKrDyycgbfeIn+gRJg1R0tBYR/P5Gn1K0PJkGe6S8g==@sourceware.org X-Gm-Message-State: APuU4Z8s/VOdl5PFBgKmX4Zt9IYSt13okoeqYo9EKJa4ON0xEFdV1Fj+ Fr0eSNqdxGiKKJbYfPHHe2EEfUZFC+l1rzEhROSY8qQ4glw7IpD8Y9+qE2GynShelc7yf6GI4dR LOGs8c9knrE8saR9cnUVAm9/29DUc1Text3YFwqX+FPEy2hB0ksxjazjCMm2BC4eoWn+2utw= X-Gm-Gg: AZFdTZccKuFFhCXjSEGj1RqpUJhwndaf8jI6PjcTS9ik0jNY0GQKSP+LRH6b3H6kuaq UCD7qVweX3IUPesCPQNaH0vRJfLt0fsTVG9rn+13f5UzYrQqKotsalhtTCyemY23aH1DpBbKaaz p61o8Ak8dGpXM+j/9zkT4oI4t9ZNaF2+HuwbBRpNnBm9wPhKtHjYfSqieICdqSgVHxC773gFnXA 0ipcHZrrMJaAtWHCFOVhaRWaC8ECxCyxD03EYSLi0KgybAjSPHYj5mIiahCbH9tTRGOVx2rG8Kb 224XyNVAoCSqrhozGvfGIYlrnqNEfujGiHL9UM9lGoPjxjH/9kEdxoEgdEplEKju0nDCeqmpazV g60XSKdDcfaNCI4txsqy7EZQTA7expKpotEnCcwQswPs7Xg== X-Received: by 2002:a05:600c:e41a:b0:4bb:9959:54b8 with SMTP id 5b1f17b1804b1-4bb9959552emr101739705e9.32.1795519612295; Tue, 24 Nov 2026 03:26:52 -0800 (PST) X-Received: by 2002:a05:600c:e41a:b0:4bb:9959:54b8 with SMTP id 5b1f17b1804b1-4bb9959552emr101739245e9.32.1795519611772; Tue, 24 Nov 2026 03:26:51 -0800 (PST) Received: from localhost ([83.216.138.189]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb853a9846sm505489025e9.11.2026.11.24.03.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2026 03:26:51 -0800 (PST) From: Andrew Burgess To: YuPeng , gdb-patches@sourceware.org Cc: tromey@sourceware.org, debianyu@163.com Subject: Re: [PATCH v2] Fix use-after-free when Python Breakpoint.stop method deletes the breakpoint In-Reply-To: <1795488876766726028.9924@kylinos.cn> References: <1795488876766726028.9924@kylinos.cn> Date: Tue, 24 Nov 2026 11:26:50 +0000 Message-ID: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 1jZ-pSsElxDUyIpe5RnQxeROIfMxNxHbIOAsDFsFka4_1795519612 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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 YuPeng 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 nullptr 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 nullptr. > - In gdbpy_breakpoint_cond_says_stop, keep a reference to the Python > breakpoint object while calling its stop method. Deleting the > breakpoint drops the reference owned by the breakpoint object > registry, which can free the Python object before the caller has > finished using it. > > Add a testsuite test in which a Python breakpoint deletes itself from its > stop method, and check that gdb does not crash and that the breakpoint > is gone afterwards. > > Tested on x86_64-linux with an ASan build: without the fix gdb aborts > with a heap-use-after-free; with it the new test passes 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. > > --- > > Andrew, > >> This will for sure need a test adding to the testsuite. You could look >> at gdb.python/py-breakpoint*.exp for inspiration. > > You're right. v2 adds gdb.python/py-breakpoint-delete.{c,exp,py}. The > test creates a gdb.Breakpoint subclass whose stop method calls > self.delete() and returns False, then continues to the end of the > program and checks that the breakpoint is gone. With an ASan build the > new test aborts with a heap-use-after-free before the fix and passes > with it applied. > > Writing the test also turned up a second dangling reference: when the > stop method deletes the breakpoint, the breakpoint object registry > drops the last reference to the Python object while > gdbpy_breakpoint_cond_says_stop is still using it. v2 therefore also > keeps a reference to the Python breakpoint object across the stop > call. The new test hits this case as well. > >> GDB style uses nullptr not NULL. > > Fixed in v2, thanks. > > Eli, > >> Thanks, but could you tell if the patch and the description were >> generated by LLM, by any chance? > > I prepared the patch and the description with the help of an AI > assistant, and I reviewed and tested the result myself. Thanks you for preparing this patch, and the updates with a test. Unless I've missed a policy change, then unfortunately, if an AI has written any significant part of this patch, it cannot currently be accepted into GDB. I really hope this position will change soon. If I'm wrong about the current GDB position then hopefully someone will jump in and correct me. I know this is not the answer you would have hoped for. Thanks, Andrew