From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by sourceware.org (Postfix) with ESMTPS id 0A79C385828D for ; Mon, 19 Jun 2023 08:07:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A79C385828D 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=1687162035; x=1718698035; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=QQqjF9eIsZQZpC21/ceVd+G7RJ/aae27htpCMD/i2Uk=; b=IYkCsYlbYOuEHxSbaiuj9AG6U+zXhiV0xg8yqLQWw3sobRwGRLzPeR0I 1/8lHS1qGPwELMxp4+giOkiLgJpdkCh95yhw5xS+JAjPzGtqUgl7cbvDm li68q29MlyXSnzmpUxidoIe2qR6j7AiyK9ANQ0FLJoZaNW26Ldel4qdqm 7lZunJJNTBmWo6uDLLIiVOuF256W3vIlVmkQ4UW0ZJqGsdLZoQOVuMkf4 SUx52CIbTaBLRJH4XSjRDiTZwP0JT+el7QpmaNH3AEghUSzNcVX14Ecl+ cT0aByIkpdy3US4afBKdIGUzrC7dgMP3QwagXCJhI8LVnQ/rzslcOwGAT w==; X-IronPort-AV: E=McAfee;i="6600,9927,10745"; a="358446313" X-IronPort-AV: E=Sophos;i="6.00,254,1681196400"; d="scan'208";a="358446313" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2023 01:07:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10745"; a="960350493" X-IronPort-AV: E=Sophos;i="6.00,254,1681196400"; d="scan'208";a="960350493" Received: from shvmail02.sh.intel.com ([10.239.244.9]) by fmsmga006.fm.intel.com with ESMTP; 19 Jun 2023 01:07:12 -0700 Received: from pli-ubuntu.sh.intel.com (pli-ubuntu.sh.intel.com [10.239.159.47]) by shvmail02.sh.intel.com (Postfix) with ESMTP id B0F271006F2B; Mon, 19 Jun 2023 16:07:11 +0800 (CST) From: pan2.li@intel.com To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, rdapp.gcc@gmail.com, jeffreyalaw@gmail.com, pan2.li@intel.com, yanzhang.wang@intel.com, kito.cheng@gmail.com Subject: [PATCH v1] RISC-V: Fix out of range memory access when lto mode init Date: Mon, 19 Jun 2023 16:07:10 +0800 Message-Id: <20230619080710.1536456-1-pan2.li@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.2 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,T_SCC_BODY_TEXT_LINE 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: From: Pan Li We extend the machine mode from 8 to 16 bits already. But there still one placing missing from the tree-streamer. It has one hard coded array for the machine code like size 256. In the lto pass, we memset the array by MAX_MACHINE_MODE count but the value of the MAX_MACHINE_MODE will grow as more and more modes are added. While the machine mode array in tree-streamer still leave 256 as is. Then, when the MAX_MACHINE_MODE is greater than 256, the memset of lto_output_init_mode_table will touch the memory out of range unexpected. This patch would like to take the MAX_MACHINE_MODE as the size of the array in tree-streamer, to make sure there is no potential unexpected memory access in future. Signed-off-by: Pan Li gcc/ChangeLog: * tree-streamer.cc (streamer_mode_table): Use MAX_MACHINE_MODE as array size. * tree-streamer.h (streamer_mode_table): Ditto. --- gcc/tree-streamer.cc | 2 +- gcc/tree-streamer.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/tree-streamer.cc b/gcc/tree-streamer.cc index ed65a7692e3..a28ef9c7920 100644 --- a/gcc/tree-streamer.cc +++ b/gcc/tree-streamer.cc @@ -35,7 +35,7 @@ along with GCC; see the file COPYING3. If not see During streaming in, we translate the on the disk mode using this table. For normal LTO it is set to identity, for ACCEL_COMPILER depending on the mode_table content. */ -unsigned char streamer_mode_table[1 << 8]; +unsigned char streamer_mode_table[MAX_MACHINE_MODE]; /* Check that all the TS_* structures handled by the streamer_write_* and streamer_read_* routines are exactly ALL the structures defined in diff --git a/gcc/tree-streamer.h b/gcc/tree-streamer.h index 170d61cf20b..51a292c8d80 100644 --- a/gcc/tree-streamer.h +++ b/gcc/tree-streamer.h @@ -75,7 +75,7 @@ void streamer_write_tree_body (struct output_block *, tree); void streamer_write_integer_cst (struct output_block *, tree); /* In tree-streamer.cc. */ -extern unsigned char streamer_mode_table[1 << 8]; +extern unsigned char streamer_mode_table[MAX_MACHINE_MODE]; void streamer_check_handled_ts_structures (void); bool streamer_tree_cache_insert (struct streamer_tree_cache_d *, tree, hashval_t, unsigned *); -- 2.34.1