From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677583867; x=1709119867; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=qwt2zBpsFeMf3Fmk3iiHJcXOlP3BvBtPokPfCNyIXnM=; b=DMtAf259itQ79O4/1lH5IVYCUe5cBrFPzQZl50hhUY6s1Oh9QZjr8b22 i1EUt6FdBc0a796/645TYTfz6lDKD8n27yUULJI81m1aQWSEZB0nS4iK8 o40N0HvOM7Hmwy7/12cHexoxiSf5MEa2C8/FfLQ/Oi+MWTZai4issTcYI LysBjO063gzHE1/o+wvFuFP0uI0dyf6RvQMs8rqqZ6aj4UlucmzoOxbvk D4krbtbFrzGGnxOINrKiLpdapym3fb5IgyAMRCflYd1y3fA/r/Q+u1RuY WtRat74fWtb43X1yeXwp21BtX7E4hqOitG7KYVdvrEgM3jDGK4vinar8g g==; 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 From: Tankut Baris Aktemur 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-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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