From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id UAVZLkfm/WPLeAAAWB0awg (envelope-from ) for ; Tue, 28 Feb 2023 06:32:23 -0500 Received: by simark.ca (Postfix, from userid 112) id BA26C1E222; Tue, 28 Feb 2023 06:32:23 -0500 (EST) 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=GRmuddjS; 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=-7.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.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 4D0F41E128 for ; Tue, 28 Feb 2023 06:32:23 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0152B385B501 for ; Tue, 28 Feb 2023 11:32:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0152B385B501 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677583943; bh=gIjob7XCXmkda0pa2BnCwm7LLSlpPuA3IoSZHsps8ZY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=GRmuddjSAxKaCjmOtbXZR+ikvBKNnYmFoYuFJIVF9/TImsovTrTMYWk0OM814OW1P bnfERmPq+cN3bTLKKyDvbQSuY1bBuTa1xVDHWE3BV+GHI3Pa1Dy/XSSJNPw647QRIP aKxpLQnvW1ohPcr8Gvqqr2uxwMSCro9f9D2z6/Lk= Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by sourceware.org (Postfix) with ESMTPS id 26C96384B10F for ; Tue, 28 Feb 2023 11:31:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 26C96384B10F X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="336401728" X-IronPort-AV: E=Sophos;i="5.98,221,1673942400"; d="scan'208";a="336401728" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2023 03:31:06 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="817058248" X-IronPort-AV: E=Sophos;i="5.98,221,1673942400"; d="scan'208";a="817058248" Received: from ultl2604.iul.intel.com (HELO localhost) ([172.28.48.47]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2023 03:31:04 -0800 To: gdb-patches@sourceware.org Subject: [PATCH 22/26] gdbserver: zero-out register values in regcache-discard Date: Tue, 28 Feb 2023 12:28:20 +0100 Message-Id: <877c74ccb7fb99d36242d9246d2824f181752a5a.1677582745.git.tankut.baris.aktemur@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Tankut Baris Aktemur via Gdb-patches Reply-To: Tankut Baris Aktemur Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Zero-out register values when a regcache is discarded so that we avoid garbage values left in the buffer. --- gdbserver/regcache.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc index 2befb30e337..644f436c681 100644 --- a/gdbserver/regcache.cc +++ b/gdbserver/regcache.cc @@ -136,6 +136,7 @@ regcache_invalidate (void) void regcache::discard () { + memset (registers, 0, tdesc->registers_size); #ifndef IN_PROCESS_AGENT memset ((void *) register_status, REG_UNKNOWN, tdesc->reg_defs.size ()); #endif @@ -149,16 +150,17 @@ regcache::initialize (const target_desc *tdesc, if (regbuf == NULL) { #ifndef IN_PROCESS_AGENT - /* Make sure to zero-initialize the register cache when it is - created, in case there are registers the target never - fetches. This way they'll read as zero instead of - garbage. */ this->tdesc = tdesc; this->registers - = (unsigned char *) xcalloc (1, tdesc->registers_size); + = (unsigned char *) xmalloc (tdesc->registers_size); this->registers_owned = true; this->register_status = (enum register_status *) xmalloc (tdesc->reg_defs.size ()); + + /* Make sure to zero-initialize the register cache when it is + created, in case there are registers the target never + fetches. This way they'll read as zero instead of + garbage. */ discard (); #else gdb_assert_not_reached ("can't allocate memory from the heap"); -- 2.25.1 Intel Deutschland GmbH Registered Address: Am Campeon 10, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928