From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id aH1eByUd6WLaEx8AWB0awg (envelope-from ) for ; Tue, 02 Aug 2022 08:48:37 -0400 Received: by simark.ca (Postfix, from userid 112) id 19CC71EA05; Tue, 2 Aug 2022 08:48:37 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Dj7YgQCd; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id A8B811EA03 for ; Tue, 2 Aug 2022 08:48:36 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A1663852768 for ; Tue, 2 Aug 2022 12:48:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A1663852768 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1659444516; bh=xXUO6XXkpg+OMTJQ6BrZe2/mqPmFU2oZ/2WGJ4K/4LQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Dj7YgQCdM3lA3zlbf6r0DAAsXKwiw+geyCFqNNTk39svhQkQQpq5Jp4gAZXMUCvAK tuipyyGrogkdjTALDkGePw6heCGDRBH43v3ZNRzk/daW9Ur8oZ/xJeloP/OldzclCo ZuH6SQv+AzJeZnH4iJEmm1v5XQgwQQkjAi/1emyU= Received: from lndn.lancelotsix.com (vps-42846194.vps.ovh.net [IPv6:2001:41d0:801:2000::2400]) by sourceware.org (Postfix) with ESMTPS id D94FF3856263 for ; Tue, 2 Aug 2022 12:47:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D94FF3856263 Received: from octopus.. (unknown [IPv6:2a01:e0a:535:2750:1299:7061:a63:c92]) by lndn.lancelotsix.com (Postfix) with ESMTPSA id 0419F8980D; Tue, 2 Aug 2022 12:47:45 +0000 (UTC) To: gdb-patches@sourceware.org Subject: [PATCH 1/2] gdb: Fix regression in varobj recreation Date: Tue, 2 Aug 2022 13:47:23 +0100 Message-Id: <20220802124724.284096-2-lancelot.six@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220802124724.284096-1-lancelot.six@amd.com> References: <20220802124724.284096-1-lancelot.six@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.11 (lndn.lancelotsix.com [0.0.0.0]); Tue, 02 Aug 2022 12:47:46 +0000 (UTC) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Lancelot SIX via Gdb-patches Reply-To: Lancelot SIX Cc: lsix@lancelotsix.com, Lancelot SIX Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" "bc20e562ec0 gdb/varobj: Fix use after free in varobj" introduced a regression. This commit makes sure that the varobj object does not keeps stall references to object being freed when we unload an objfile. This includes the "valid_block" field which is reset to nullptr if the pointed to block is tied to an objfile being freed. However, at some point varobj_invalidate_iter might try to recreate varobjs tracking either floating or globals. Varobj tracking globals are identified as having the "valid_block" field set nullptr, but as bc20e562ec0 might clear this field, we have lost the ability to distinguish between varobj referring to globals and non globals. Fix this by introducing a "global" flag which tracks if a given varobj was initially created as tracking a global. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29426 --- gdb/varobj.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gdb/varobj.c b/gdb/varobj.c index e558794617a..0683af1991e 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -102,6 +102,9 @@ struct varobj_root to symbols that do not exist anymore. */ bool is_valid = true; + /* Set to true if the varobj was created as tracking a global. */ + bool global = false; + /* Language-related operations for this variable and its children. */ const struct lang_varobj_ops *lang_ops = NULL; @@ -336,6 +339,8 @@ varobj_create (const char *objname, var->format = variable_default_display (var.get ()); var->root->valid_block = var->root->floating ? NULL : tracker.block (); + var->root->global + = var->root->floating ? false : var->root->valid_block == nullptr; var->name = expression; /* For a root var, the name and the expr are the same. */ var->path_expr = expression; @@ -2359,7 +2364,7 @@ static void varobj_invalidate_iter (struct varobj *var) { /* global and floating var must be re-evaluated. */ - if (var->root->floating || var->root->valid_block == nullptr) + if (var->root->floating || var->root->global) { struct varobj *tmp_var; @@ -2375,7 +2380,7 @@ varobj_invalidate_iter (struct varobj *var) varobj_delete (var, 0); install_variable (tmp_var); } - else if (!var->root->floating) + else if (var->root->global) { /* Only invalidate globals as floating vars might still be valid in some other frame. */ -- 2.34.1