From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by sourceware.org (Postfix) with ESMTPS id 359043858D28 for ; Mon, 19 Jun 2023 09:08:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 359043858D28 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=1687165704; x=1718701704; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=nrz5llKE/IylUhz5VHSFbRBgzbcXShmMLmE6EopHThA=; b=XSElldfg8tZd+SbRorz5ZILKfe91zv+6+yB0r2ziReXOBJDpmPK0+IvJ SHO+U9oKUVsTJLdBmjc93ZlZ87h/c6yaMPGO6nQWmGRu7JsoUtwtjlYPa WsyLAjRyQ8Hf6z9yY/4LK3sdy8S221iLOJsDxtFa1xWXCN7Uwdfe/aD5r PlA3iW/pLAAw1stOt56X+dv93OcdxtG0XsrIYTgGI/Sgfov0eUijqJGB4 luMtHWmZd5l5TKzsJkC5OQXwyp7i8byhDeIqoXyhJODjlwASRd1wQREEs HGULSk/WLngNZR1kRBb1wv7KikREC1xZGjWp4o3E7LZu3MAucSM5y1o+o A==; X-IronPort-AV: E=McAfee;i="6600,9927,10745"; a="349303670" X-IronPort-AV: E=Sophos;i="6.00,254,1681196400"; d="scan'208";a="349303670" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2023 02:08:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10745"; a="837805043" X-IronPort-AV: E=Sophos;i="6.00,254,1681196400"; d="scan'208";a="837805043" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by orsmga004.jf.intel.com with ESMTP; 19 Jun 2023 02:08:23 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 19 Jun 2023 02:08:22 -0700 Received: from orsmsx601.amr.corp.intel.com (10.22.229.14) by ORSMSX610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 19 Jun 2023 02:08:22 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Mon, 19 Jun 2023 02:08:22 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.171) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.23; Mon, 19 Jun 2023 02:08:22 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ip6lH8vSisPo9d1n6t0nbXo8WP4J/aMqw5knxNd0ALbL0q8YHpegXdPVVu5DIRV/i6ZERExEl2nShRzn05RX52YrC6XGUX/V5j7jYO1WaLLtdJScTjm3/aLpyCYvKzdrc/GAniGmlgpdvyX/cVJya+9Njg7vR1v4HjlBMu/tEy3KHHqe+5tj4YBZN1hGBS+FK82+ezjmFutWGZxKD2jeMiTnjYGkRfG9Yw/Hr4jtKNeGAqFPmPUJYLbVX1/B96waxurOhew7/OVDSqDLjCXs6D5TDTvCUhc4hE9yTF5N9ptoJ1Dp+HW68kgeW1fEwMV+hr+mI6ZXWzfLkS7z4FoF8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FzBpK1nau4/peGXL2+UvlmxiuAcasWGO+J3Jr6+nrl8=; b=AsQtkiPMkF9hbXOBJC6PuHdYF+Rs0hQ6yLQriOkkCg4Mtlb4AXJSfvkBElGUVD6m/jOPAxS75kzP1layn7WqZRAvVnqIbpP1gurIPuUQjZYNDB/I3GT8ZRo+wH5DFj8oLp8+K20B3kVLe1F3DjevG4dB7luKXgzjzPtbU7uROHqk0S88GXRadIcnG7G4Xd0f2iXIQVmYkZ5+yAHEvV7+zdX3HG6D9TkVwQcRpVJG2xDwHQ6PHUh43TV9d3iy+I2iiSeU8EOW6taswGe98b+6D9GcJF8y6RnSkS0eagGczYageGoIrYht1yNDSvIxxXBVA8yXfyqdjK+pW73eE0J7BA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from MW5PR11MB5908.namprd11.prod.outlook.com (2603:10b6:303:194::10) by DM4PR11MB7327.namprd11.prod.outlook.com (2603:10b6:8:105::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.37; Mon, 19 Jun 2023 09:08:20 +0000 Received: from MW5PR11MB5908.namprd11.prod.outlook.com ([fe80::127c:f4cc:e699:8f73]) by MW5PR11MB5908.namprd11.prod.outlook.com ([fe80::127c:f4cc:e699:8f73%6]) with mapi id 15.20.6500.036; Mon, 19 Jun 2023 09:08:20 +0000 From: "Li, Pan2" To: Richard Biener 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 Thread-Topic: [PATCH v1] RISC-V: Fix out of range memory access when lto mode init Thread-Index: AQHZooUcMSti0htIAEK2MR0qr77m36+Rxt1ggAAHogCAAAcAAA== Date: Mon, 19 Jun 2023 09:08:20 +0000 Message-ID: References: <20230619080710.1536456-1-pan2.li@intel.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MW5PR11MB5908:EE_|DM4PR11MB7327:EE_ x-ms-office365-filtering-correlation-id: 6f83cfe8-812a-4b2a-aa01-08db70a4ba1e x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: yi8xmf/AW7ov36nsfv5ZAFWMyhYiViJwoeHExfBC+mwo2nTANpAMeE7AdsY9targLThJvQb78uWDhVfeCGXuNFJL7tHTYA6sNFk8J/9r5tAmiihvaWXHzZh3musntWXXEVuPdQZZHYe64eDF+CzkIEPi1IIAjMsJ5QCxkOj18zEw5H2+4T5PlWf8TSMlGFs6tvxGuw8Ot6SRc6JRzIaNaK1GDsV5PUh+64hmYb1eEcWik5LhjmQkQwSi3/MVOWr7LpjAOP83FDEt+OPEy6ql7zJFfyUjF1N8b8FCE6hJhmA5s+nmN2FS6kS+Ln7lJj9hj4HH7nV+AeJH00T1+8C34qyzxbB5uUgvHaCXXV46gbtZF1MoaSrQodJLazQrnZuM1vNXTYYe4rGJYbgjwxtCMFHphLQlG1GguLSlF1qomwZa8uYUJ7em1qVESnND/ZByYPa1TT7JT8cv5l6G9kEH0gxKmAn6NweVtO2oSRCggsKjhccFT7U31R6r8pXTddYszqurgj0t/+nypBaPO9UqznwT6UUXvbGLt5xKDBEDe+mkUmUyJRtGYs+mfF5njjKRYP9wsoFuFVSN/mN84iiDeYiylYoB8rqrPQykS9uMK1A= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW5PR11MB5908.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(396003)(346002)(39860400002)(366004)(376002)(136003)(451199021)(186003)(8676002)(8936002)(66946007)(66556008)(64756008)(66446008)(66476007)(76116006)(5660300002)(54906003)(4326008)(71200400001)(7696005)(33656002)(316002)(38100700002)(478600001)(41300700001)(966005)(26005)(53546011)(9686003)(6506007)(6916009)(55016003)(122000001)(38070700005)(86362001)(83380400001)(2906002)(52536014)(82960400001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?mcVEXd9lj6jVOlXPHMf+6gXekE/ciDR1lg8X5LtGE0QtK/bLLqtiujgoj1Zm?= =?us-ascii?Q?FjsL9qV5Q3ioHpPjiwbF2jdzGC5fSDjOWldKEDAsBdI/sMdNL5VtxmpMgnXH?= =?us-ascii?Q?2UfyoDqTOHHyti7VgZ3LZyD4enzdsmEaxxh6onUmwam4GHyOy+oB9U74aBe7?= =?us-ascii?Q?9wB0SxbHroJADcuWUGG2NKukP+zgooVYEwv0s4HysG560xwuYJUNdvushLD6?= =?us-ascii?Q?z50pyMX4FFmjyiuqQrS5Aqq0MuuKv505Ih4piy0wfn04BnnbTUSqJ5PJJpY/?= =?us-ascii?Q?S+d6hA9IcDzsptL7ObnkFF3ijyv+vdv5XwqQsxE2P+JWZ3xOknWNwhzVMJ6O?= =?us-ascii?Q?+VyEyqN/SGQRw1+gyI3yOhsYcK5SP9hEXvS49dtKl5Jny+3d+82vr3H712D4?= =?us-ascii?Q?+7WmRHweDW/Vx5uXV4DOFnpPxK4OhTd7HKAWdP2sg75Vy55HAl1XJjzF0NWM?= =?us-ascii?Q?+g5t3YEiHxfY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d?= =?us-ascii?Q?koNgy8yoX5AfzOtUhzHmspkh+y9hC4MYMRC0jaKXjNyB7KKJdkViTmMaGKYM?= =?us-ascii?Q?6+Byj9PwnDkHBQ4Q3bD7rgtBlLkvY2lBThMwTNavrEQ6K1s8oxvIrGxF077m?= =?us-ascii?Q?eDPg7+Swbml5gl9VtSmGqtWBV25Wj7+xeIO6QhDOJ5nWVXKuQcZCbi4JAINg?= =?us-ascii?Q?yy7C3MpaU4TVmT78qeM=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW5PR11MB5908.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6f83cfe8-812a-4b2a-aa01-08db70a4ba1e X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jun 2023 09:08:20.2078 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: M7xsWqUXuUAcssT30z3pgPW4Wy3vEZpTWN3eDEJQvXT6J5Oy8cvX5L48ZCcgRsr0OY8+oxZMjnqS4/O118asDA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB7327 X-OriginatorOrg: intel.com X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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: Thanks Richard for the review, just go thru the word (1 << 8) and found ano= ther one besides bp. Update the PATCH v2 as below. https://gcc.gnu.org/pipermail/gcc-patches/2023-June/622151.html Pan -----Original Message----- From: Richard Biener =20 Sent: Monday, June 19, 2023 4:41 PM To: Li, Pan2 Cc: gcc-patches@gcc.gnu.org; juzhe.zhong@rivai.ai; rdapp.gcc@gmail.com; jef= freyalaw@gmail.com; Wang, Yanzhang ; kito.cheng@gm= ail.com; Jakub Jelinek Subject: RE: [PATCH v1] RISC-V: Fix out of range memory access when lto mod= e init On Mon, 19 Jun 2023, Li, Pan2 wrote: > Add Richard Biener for reviewing, sorry for inconvenient. >=20 > Pan >=20 > -----Original Message----- > From: Li, Pan2 =20 > 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.c= heng@gmail.com > Subject: [PATCH v1] RISC-V: Fix out of range memory access when lto mode = init >=20 > From: Pan Li >=20 > 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. >=20 > 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. >=20 > 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. >=20 > 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 >=20 > gcc/ChangeLog: >=20 > * 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(-) >=20 > 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]; > =20 > /* Check that all the TS_* structures handled by the streamer_write_* an= d > 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 *, t= ree); > void streamer_write_integer_cst (struct output_block *, tree); > =20 > /* 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 *); >=20 --=20 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)