From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id EbMKMm4i/2pOjiAAWB0awg (envelope-from ) for ; Thu, 19 Nov 2026 11:23:10 -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=ioaDKlMG; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id C7FA51E023; Thu, 19 Nov 2026 11:23:10 -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,RCVD_IN_MSPIKE_H2 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 EE0111E023 for ; Thu, 19 Nov 2026 11:23:09 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 882194BA2E3E for ; Thu, 19 Nov 2026 16:23:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 882194BA2E3E 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=ioaDKlMG Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 857004BA5434 for ; Thu, 19 Nov 2026 16:22:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 857004BA5434 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 857004BA5434 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795105364; cv=none; b=rwc2N9rQUvZlPmuwHB+aGI1tazxZ20QhrQGlVNXFtsh0hAWxNYANGGJgV7H8VGQGa/PL3RaP95toP+txAjxMOBoPo0ppSe01gA7J+faIaoQDlFnrEXQaikzoMpWjla1vBHaha/zWJt/yW8fpiW43PMmKDh2001xHdrXDnVA4tZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795105364; c=relaxed/simple; bh=UFexncopQYgCbSpZgv4ZkGxtwbLZb337XIWAxd63l6o=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=YpkgyRKrtq5p2GPEK7JN+4CRwGSuM7XajYvoX/bEi4F5tP6XGwX/nswFFf+QL6HTMq5vMgYfhVW4P3qKsaJGda6xurH/eKLY+8qX/zbbOXBLGxrJhixuGva0+lf9/NEpr3oly3BS4Wss6vpvg/KrQocdMQgXCRrJGq8+ATt3bkY= 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=ioaDKlMG DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 857004BA5434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795105364; 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=TdfvJOZkRkbsyjcwQIAS9xlbUtMU3xTzNJ9Mb3yswmM=; b=ioaDKlMGSRmBFcFuT9tAZ7gEcTEDAcQ0k3/aO17bK28uWkSJtOn3dN74qOaXf2bp1aBQqM QuFXnPsZABb/BV3EDD8HCUfiodCvwUEmK2XCo7afPlGAthj9UsRGRXQlbMNSCO9emPxPP3 N8QtSHx+DCiSXJSAaiYaJ3K+OBb+7DI= 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-83-VcrLQ02wO2uzhaXGxbC3mQ-1; Thu, 19 Nov 2026 11:22:42 -0500 X-MC-Unique: VcrLQ02wO2uzhaXGxbC3mQ-1 X-Mimecast-MFC-AGG-ID: VcrLQ02wO2uzhaXGxbC3mQ_1795105360 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-4a7c864000eso1187752f8f.0 for ; Thu, 19 Nov 2026 08:22:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795105360; x=1795710160; 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=TdfvJOZkRkbsyjcwQIAS9xlbUtMU3xTzNJ9Mb3yswmM=; b=QQZ1wSlfYYc585wo6a/qEx+xu3HiLdDLqCjTWJAkgLQUezlYpOzX+vB8hY+iiRTG58 GrS6FwB/keHPYTweGlsGLXPRT4EedOTyJv1KFQOtvSKvBV3Pd40NWtT3sKzu0PS5DJe3 tjfZVmQ+UetzP1QlQheUI/ufdMSXygrgLMmE+7Am6oc/375m9ORwT1RWQYZt4IH3fey6 xSj499LX3ZEBosUFpdocCmYbDc5uZNNnyGjSuU3mVZtTroRSIBoSZT0jH/qmOvIGKTuZ 0q/XE2bIWkU8xoGqea2ghTrX673mmDRL78Id5GR9lndROQ8klzyWzmr1tXjNSnHqJWGK WSGw== X-Forwarded-Encrypted: i=1; AL+hErHsl6Bdbp8MVr8OU6AbAGdwUQzs+Nk7JNrIfpr2i+6e1l9JH3llIhN8BS2FBg/AHpSTPbk/kEJGiuR9mQ==@sourceware.org X-Gm-Message-State: APuU4Z8CXEQPjXD9cXWiiqjZltDrm6cXbru6Tirp65hNHmY6jFH/ZmeG DYOsy09G7codVZzVyfFaytDw/hXeRFfVMZ1C8G5nXS/0Jf+m0gZzDR5HQprQNLBKbwRVVe+Zeev /ZT79sd/8nmHB6goUyofZXj10cuZ2sZdbWX4XrNz3xgE3FTbkoNX0hbpdyo5VlAA= X-Gm-Gg: AZFdTZcpth9Dxea6Cjm+AhjQhY5GfCtHjsWCda5Mcl6xQg1HVC6KycGzw7kwN4zrb9Q G0Oh8hQ+gaAkCPQbtqF5Q/XDuKR3sue5N2KnAwhsSLOmTjySpvvzMkVFxtDCXPpfPSC1ExAI28b EY0u3Seyr1G0JrvYnyHXUB3za5JAF/z8G37ZVdYdnNxUqOInLTKL3bDD/KmBgObrjdzncwr3lRo nMu0YyzvtmdMApvJrBF4b+AEAPinrhDCkzF3q0H6zjgv+4zkzAg+tcHmWJ3q3kz5UwdwW8EZvYN g+DwKX1E0dGbUDu5XfmIEWAyV2gSf0A94bissewmw37YGoLcD0rFdUy/6v9I17TGVqiGMMFRHTM 3X5R/8KXbH35R3jXOXSIBo7h1hkv3rYrqdKjHOsGSwa8BDA== X-Received: by 2002:a05:6000:2905:b0:4aa:842f:5f84 with SMTP id ffacd0b85a97d-4aa842f6232mr4461865f8f.42.1795105360339; Thu, 19 Nov 2026 08:22:40 -0800 (PST) X-Received: by 2002:a05:6000:2905:b0:4aa:842f:5f84 with SMTP id ffacd0b85a97d-4aa842f6232mr4461812f8f.42.1795105359897; Thu, 19 Nov 2026 08:22:39 -0800 (PST) Received: from localhost ([83.216.138.189]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6b110ba3sm328426f8f.35.2026.11.19.08.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2026 08:22:39 -0800 (PST) From: Andrew Burgess To: YuPeng , 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 In-Reply-To: <1794998055185602167.295606@kylinos.cn> References: <1794998055185602167.295606@kylinos.cn> Date: Thu, 19 Nov 2026 16:22:38 +0000 Message-ID: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: IKMcOIxA0HrMC96HEd-e5EJbtbsWrRbKxLxhghHGcIE_1795105360 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 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