From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gmbaNmAt62rk8RgAWB0awg (envelope-from ) for ; Wed, 04 Nov 2026 08:04:32 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=W2kL6Mq2; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id CD604378002; Wed, 04 Nov 2026 08:04:32 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.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_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED 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 DC1EB1E052 for ; Wed, 04 Nov 2026 08:04:30 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 723864BA2E31 for ; Wed, 4 Nov 2026 13:04:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 723864BA2E31 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=W2kL6Mq2 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by sourceware.org (Postfix) with ESMTPS id 0353A4BA2E18 for ; Wed, 4 Nov 2026 13:03:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0353A4BA2E18 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0353A4BA2E18 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793797439; cv=none; b=l6TUsaT+oQoNAP0J3VtRYjGOx2nPD1wTCTP9ll1m1RBAmy6BHYbwQql0RFuRmbB3bOMmjlt3aO1lKwIiDAFMq9Q7SuLvUklNp0jki5yJhbOMmwAQEKlQs1xUpZn164wRFhPhlUBk9LexyjgE0lEJ2LbNQVimRV97JJOpFx6nFM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793797439; c=relaxed/simple; bh=WaEF54Cr9GQk8zU3t6f5kgWDNIuefAXhJ1pwyUE2h/4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=PAUgeMA7bNULPJFVDXaeborilUoolnaHfGAzSsN4CZMQakAQ4bAL8HtE+rHRUd7PbT4SRr9Ze81/YJHZFez67B/+MquyFVLIK80WCejwlZWthAyGXRryRTigiCYW1yV26yF/Gpra8ntXmoPgnR7XsBjSzYIjDYLFQa9Rnv6s9wg= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=W2kL6Mq2 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0353A4BA2E18 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1793797439; x=1825333439; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=WaEF54Cr9GQk8zU3t6f5kgWDNIuefAXhJ1pwyUE2h/4=; b=W2kL6Mq228yg0oYV2F/V9SJVPttgGckhcJ9USLh4U9IhjKPA53s5ce6+ c+GeLXa+/iFOfl+uWDaQd1o1QCbpqSlW0eJ69C/W4R41dxSWKr0m1ZtJc 2Z+cUv/GE5Wax2zllPNFW3mg3RKgpnS5XmVPSxWe9usU93yvFPQ/oWQFw 5oM0i3pn22K90uvwQHVWUMb7lVLe0WQWlTYkaqnPrTfsxfnmBDGnkpviz hjM1BaDgWAMVH/9UIThrgVhhCw2YpbfQMrSJd/bk433Dzzu9fd7KMu06r 6n/x0FOdzqnJarE9ez50TKhDlzYZR+h/o6V2KZk7EJmBBG8UOx+Q3RwsY g==; X-CSE-ConnectionGUID: I29HXEGUTXqA2wI40Y0Xkg== X-CSE-MsgGUID: X9CXQAE+QL6E6nYigLBY7w== X-IronPort-AV: E=McAfee;i="6800,10657,11955"; a="2543899" X-IronPort-AV: E=Sophos;i="6.27,195,1787036400"; d="scan'208";a="2543899" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2026 05:03:58 -0800 X-CSE-ConnectionGUID: 3yMiWQFPT0KPZo0/mU9WMA== X-CSE-MsgGUID: xv0gUBCmQHanxYpLIJ3zJQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,195,1787036400"; d="scan'208";a="6854947" Received: from dut1048pvc.igk.intel.com (HELO localhost) ([10.211.177.228]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2026 05:03:56 -0800 From: Stephan Rohr To: gdb-patches@sourceware.org Cc: tom@tromey.com, guinevere@redhat.com Subject: [PATCH v3 0/1] gdb: fix assert after register write failure Date: Wed, 4 Nov 2026 13:03:43 +0000 Message-ID: <20261104130344.44218-1-stephan.rohr@intel.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 From: "Rohr, Stephan" Hi Tom, all, thanks for the feedback. I can confirm the use-after-free issue you found. The proposed patch now wraps the target_store_registers call in a try-catch block. It invalidates the register only if the error is not a TARGET_CLOSE_ERROR. I checked the "store_registers" implementations for other targets. As far as I can tell from reading the code, the ravenscar target has the same use-after-free bug when the target beneath is a remote target, see ravenscar_thread_target::store_registers (): temporarily_change_regcache_ptid changer (regcache, base); beneath ()->store_registers (regcache, i); If the remote write fails in beneath ()->store_registers (), the destructor of temporarily_change_regcache_ptid calls set_ptid on the already destroyed regcache. fetch_registers and prepare_to_store use the same pattern. I think this should be fixed separately. IIUC, on the store_registers path, the regcache can only be deleted if the remote target is unpushed, which is always followed by a TARGET_CLOSE_ERROR. If we want to be on the safe side, we could add a lifetime token to the regcache: std::shared_ptr m_lifetime = std::make_shared (0); and take a weak reference to it in raw_write before storing: std::weak_ptr alive = m_lifetime; try { target_store_registers (this, regnum); } catch (const gdb_exception &) { if (!alive.expired ()) invalidate (regnum); throw; } We have no evidence that this is needed. I think adding the try-catch block and checking for a TARGET_CLOSE_ERROR suffices. If you prefer, I can also add the token. You can find v2 of the patch at: https://sourceware.org/pipermail/gdb-patches/2026-October/231112.html and Tom's feedback: https://sourceware.org/pipermail/gdb-patches/2026-October/231275.html Changes since v2: - Removed the nullptr check and replaced with try-catch in regcache::raw_write (). - Added a testcase to gdb.server/server-kill.exp. - Reworded the commit message. Thanks Stephan Eduard Sargsyan (1): gdb: fix assert after register write failure gdb/regcache.c | 22 ++++++++++++---------- gdb/testsuite/gdb.server/server-kill.exp | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 10 deletions(-) -- 2.43.0 ________________________________________ Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 (89) 99143-0 www.intel.de Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman Chairperson of the Supervisory Board: Sonja Pierer Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.