From patchwork Mon Jun 19 08:07:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 109761 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2841561vqr; Mon, 19 Jun 2023 01:07:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Qn1lKlxy7qbfFF/YVL6BociL2ArLWkL4ZPwC6WWsA7sJvD7YtY/frciXbS1HaHZREAlTA X-Received: by 2002:a17:907:c13:b0:988:aa45:806 with SMTP id ga19-20020a1709070c1300b00988aa450806mr1060473ejc.15.1687162079728; Mon, 19 Jun 2023 01:07:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687162079; cv=none; d=google.com; s=arc-20160816; b=l1oLDjJfb2G0OXF38ITmu5HuzIal5bCRTyRjl65n2afa1iSUU0HOV6akNz26+1nN/n Tre3gvju8GKXpTEaT2/5lBbcFQOKQ+EHbm6nHTWw5zbTQ9PdT3o7O+uc982R8J9CPjt6 KptNm0bcx+LGrjumd34ZtEyw69istxEesV+8UPCr8V33BsoCBZhrEaxzFy+CESljMGgH AeIdmFowCvwQdi1V+vuVrgziqeSYKsMPe2sP8n6+qXYzuHo/FcsJb4Pd/OcKuotcnl/c uUOCzI3nKjAJzPh0RksRY+zEhqLoBSe8wekItC+E6U/HoQVruNpI29TmeY1E+/ihFl5G nZ0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=zk8cSSZ386C2HwRBcbA6KI2mOjHL/2ZyRNh8wK07+8k=; b=MXX+d1pigC+NghA8Qz1B4LoTt6BGTl+IGA4KJbmH5MXl4gRRzWvPUHBfETpl8OrH72 eD80muSLsMivc2cOiSv1bHFMsWpbvBGTl34kQoJdYTNBSkNdNahRuARwYp1tqkTCx7li nQUnKkqGGTpww9Gq2dq8EWujtbnnPu9t8xvcIAetAYOKmluOqGRz1JZSH9xJ6ldJpigN c5REMSYm2YWCNOuUW5BAa4Ha+gV/iT41FfXGJcRSt7qwQtc/03eBbr9A/1EFADlek2uW aG4tLFO+v8dB6yHtMye/6BsUuefBf/Int0jYWttAcke/rfpt9vyrIT2tbkBI8e9wxtgq UaLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PuUehomn; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id h20-20020a170906111400b00982c89fdb95si4836651eja.166.2023.06.19.01.07.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 01:07:59 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PuUehomn; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E5493858D39 for ; Mon, 19 Jun 2023 08:07:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E5493858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687162078; bh=zk8cSSZ386C2HwRBcbA6KI2mOjHL/2ZyRNh8wK07+8k=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=PuUehomnaLI7hhvMdBkz8Uc5prERsBojXaL4sqj4snFeMeXXpLMTcZgGJR+t5LUPV lml2dRTVe+btTXzaj3cuJh9PtAzbdW4yZV8M5pykT5UdfQGBFY7XZycIUeMy3wPglk qNp9i1NMQpa/iBOPPXYjtwTPPKncssBplJV8eZIc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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) 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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pan Li via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: pan2.li@intel.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769117664882646499?= X-GMAIL-MSGID: =?utf-8?q?1769117664882646499?= 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. Signed-off-by: Pan Li --- 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 *);