From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 65C8A3858D28 for ; Mon, 19 Jun 2023 08:40:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 65C8A3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 9F49C1F889; Mon, 19 Jun 2023 08:40:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1687164058; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=X/fDtvh7/QTkz6eywfDs8pneCEUPfel0x3oqlpXGlIM=; b=rhotwMscx/Z6OLAt5cE7e9f7CAosdFNJQ0OfoLHNPcnhx3hlagaRb8gMkZZVs55GnCQjgh oTV/lF0BmtQ0tvgivc8LLmiSiUv0BPbeC1yiESRsLMeWZLVqpeSPk/CB1PWbnwhiH5p+0I GIO0cYzAtFnBIk+PR9YGnvmohz8H+Bg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1687164058; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=X/fDtvh7/QTkz6eywfDs8pneCEUPfel0x3oqlpXGlIM=; b=jfCKtQPWZ01IyvainbRGWUm3r32sl4NPayXCAHz3L0hswtWfjAOQAUW5Ndp4TcztVrM7gn yCdGXsWYZYsy2XDQ== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 812A32C141; Mon, 19 Jun 2023 08:40:58 +0000 (UTC) Date: Mon, 19 Jun 2023 08:40:58 +0000 (UTC) From: Richard Biener To: "Li, Pan2" cc: "gcc-patches@gcc.gnu.org" , "juzhe.zhong@rivai.ai" , "rdapp.gcc@gmail.com" , "jeffreyalaw@gmail.com" , "Wang, Yanzhang" , "kito.cheng@gmail.com" , Jakub Jelinek Subject: RE: [PATCH v1] RISC-V: Fix out of range memory access when lto mode init In-Reply-To: Message-ID: References: <20230619080710.1536456-1-pan2.li@intel.com> User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,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: On Mon, 19 Jun 2023, Li, Pan2 wrote: > Add Richard Biener for reviewing, sorry for inconvenient. > > Pan > > -----Original Message----- > From: Li, Pan2 > Sent: Monday, June 19, 2023 4:07 PM > To: gcc-patches@gcc.gnu.org > Cc: juzhe.zhong@rivai.ai; rdapp.gcc@gmail.com; jeffreyalaw@gmail.com; Li, Pan2 ; Wang, Yanzhang ; kito.cheng@gmail.com > Subject: [PATCH v1] RISC-V: Fix out of range memory access when lto mode init > > 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. You also have to fix bp_pack_machine_mode/bp_unpack_machine_mode which streams exactly values in [0, 1<<8 - 1]. CCing Jakub who invented this code. Richard. > 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 *); > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; HRB 36809 (AG Nuernberg)