From patchwork Tue Oct 4 09:45:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsukasa OI X-Patchwork-Id: 1676 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp42550wrs; Tue, 4 Oct 2022 02:46:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM73VLdnNB7JbUuCFZn52/zUh+pFKHlzDWlb+TGX7npfuoDJ0YPYKW7yAEmuPwAKXzDSxhyW X-Received: by 2002:a17:906:9c83:b0:779:c14c:55e4 with SMTP id fj3-20020a1709069c8300b00779c14c55e4mr17973231ejc.619.1664876784570; Tue, 04 Oct 2022 02:46:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664876784; cv=none; d=google.com; s=arc-20160816; b=azuwNJJUnHlGah42MA1y3rCWUlNiFaytPIrm0EXegZQzHYWI45TrFCfUu4SjEhIHak y69ez8HhkEyEXlMr59Uf1GQbjbsVBnfVTJkHG1XRK8g86gVfN9Jnm4sbAjUC2OPSm6fc IRPui7Uzwg+jot4yXYQw2uwntQrZLdfJ8aVQT/aymjwCMTHM5cKvGjKpND68QHurR4xy ezjAm9VFuD5P7btPxTFOVUF1UADc+p76YMtxXJ7RQ8y8RH9489mwiFQQIZsGbPZusXAZ Z1dicJDGj5L7ETC98Ou78zLYveUdXV5NX6jodFbsKxY+y8JzR/EcHjsVGJfZ+entGgH+ DzHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=RrHfXr3Owp1NqQIr+LsPf0h0hD6fEJNjfHwBTh9KpLA=; b=tUJp2B7vM3pYplTadXip6G7Ia1qSqHeThRY5ZNJ5qlI9H5KxMb33H/DYMA+GilOCzu 4AtaJuf44YoNNf4BYNLXJ+LrW77/a85+gLEZgwCgb8V8M4hOL70QU/0Cu0byqOtHmYHk rDKuryofT25Y1YoRUHBwMpElJDeOG+qTBGH7efpRtHoRZh5I88aSC2QntVnO9N9mSvDS 5rxnbvNgH1n5CmldiY3TszQ0GjiJfO7peXL+26FazL+7rdfpXO4x4S9WiWGUy0QBBlk9 ptGl8AilX8PLktqCo9gehL152Qq9BrETYyB/O1I6ANzM6oMFKlaeazNkGtBl1rkcM5/W bMPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=X0AA2lW3; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gn29-20020a1709070d1d00b0078356aaeb63si3439011ejc.288.2022.10.04.02.46.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 02:46:24 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=X0AA2lW3; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3583E3854168 for ; Tue, 4 Oct 2022 09:46:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3583E3854168 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664876780; bh=RrHfXr3Owp1NqQIr+LsPf0h0hD6fEJNjfHwBTh9KpLA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=X0AA2lW3Yt7AcLSNBl2tPmQINLr9woQA/tZw19/+gUcjYvU4iiAUKJg32v6GHRvia xxFwU9ZCkG+BynqxmVIChMukU+xK7XNKI+E/wUiOwKJZLDmlESeJnxfZEvEJJAft6U /MIQbQStSTkWu7vhpDMNbCtt4rVr+MM7ljfY1XPY= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-sender-0.a4lg.com (mail-sender-0.a4lg.com [IPv6:2401:2500:203:30b:4000:6bfe:4757:0]) by sourceware.org (Postfix) with ESMTPS id F1C5238582BA; Tue, 4 Oct 2022 09:46:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F1C5238582BA Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id 39BF3300089; Tue, 4 Oct 2022 09:46:10 +0000 (UTC) To: Tsukasa OI , Nelson Chu , Kito Cheng , Palmer Dabbelt , Andrew Burgess , Jan Beulich , Andreas Schwab Subject: [PATCH v2 1/2] RISC-V: Fix buffer overflow on print_insn_riscv Date: Tue, 4 Oct 2022 09:45:49 +0000 Message-Id: In-Reply-To: References: Mime-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, KAM_MANYTO, SPF_HELO_NONE, SPF_PASS, 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tsukasa OI via Binutils From: Tsukasa OI Reply-To: Tsukasa OI Cc: binutils@sourceware.org, gdb-patches@sourceware.org Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745746991619630293?= X-GMAIL-MSGID: =?utf-8?q?1745749838865329392?= Because riscv_insn_length started to support instructions up to 176-bit, we need to increase packet buffer size to 176-bit in size. include/ChangeLog: * opcode/riscv.h (RISCV_MAX_INSN_LEN): Max instruction length for use in buffer size. opcodes/ChangeLog: * riscv-dis.c (print_insn_riscv): Increase buffer size for max 176-bit length instructions. --- include/opcode/riscv.h | 2 ++ opcodes/riscv-dis.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/opcode/riscv.h b/include/opcode/riscv.h index 9417dcf00c5..33415977bc7 100644 --- a/include/opcode/riscv.h +++ b/include/opcode/riscv.h @@ -55,6 +55,8 @@ static const char * const riscv_pred_succ[16] = "i", "iw", "ir", "irw", "io", "iow", "ior", "iorw" }; +#define RISCV_MAX_INSN_LEN 22 /* max 176-bit encoding. */ + #define RVC_JUMP_BITS 11 #define RVC_JUMP_REACH ((1ULL << RVC_JUMP_BITS) * RISCV_JUMP_ALIGN) diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c index 6ac69490b78..f5e5af3138c 100644 --- a/opcodes/riscv-dis.c +++ b/opcodes/riscv-dis.c @@ -999,7 +999,7 @@ riscv_disassemble_data (bfd_vma memaddr ATTRIBUTE_UNUSED, int print_insn_riscv (bfd_vma memaddr, struct disassemble_info *info) { - bfd_byte packet[8]; + bfd_byte packet[RISCV_MAX_INSN_LEN]; insn_t insn = 0; bfd_vma dump_size; int status; From patchwork Tue Oct 4 09:45:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsukasa OI X-Patchwork-Id: 1677 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp42677wrs; Tue, 4 Oct 2022 02:46:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6SL8tZkQfmA9VFzZrg9lOYb27Zjf/RyKm7dvA0BE9yskTN864IZ3+5a1UvEonR+lRfT/uC X-Received: by 2002:a17:907:7287:b0:783:ad45:27aa with SMTP id dt7-20020a170907728700b00783ad4527aamr18210860ejc.99.1664876806445; Tue, 04 Oct 2022 02:46:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664876806; cv=none; d=google.com; s=arc-20160816; b=le9EPYRql9ZIMX6HNTwPEHk0w5NHXoXBRz2J7mO83p51xmFTRNrGJjSbOC12LYEigy 2QAJ2Jo0Ir3EvmvOyYqZNX2mK1ZyWqnkglyKvXxc/p21vL9eP6wY6sE1zuFyNXd1pxi3 1I1rPT1vBUjYZYiBdhGIQglhFQ9b8d3O533Q+VxhOFghvWw14IBDlZBLjQX0Smn4Kv5F m6UCxH3aMbH59waPCMnGD9jWf1djlqOd7F684RDMSloNWQlwT17yagCVOVMj32joYkZH bftgmnHgFJmV7Ji5YFE2zDj6Gf381kAidMNJMZdlUU9BiMFeBpDwy04SK+NffDDohhgv nRog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=ORE6MwU/WXwXXj2EPipdnDlfxgTJztsz5Pf/z3YDIA8=; b=rHPCcyxEYJbpbbhaGuprJpt0GCYvlwsyDKkLPC0DC6aOFAM/W5NXBtxpJDIyTYgBGp 620vThfpfBz+M5XeaWB40eTxk0Uqd3ppt6mybqSYN7n4y9iP0BimE0GObJk2trLNSShj DU5wfss4NQBuxoEGH64bViob49OUcfiYea0oFihuijTKxyBLCixIzyRs8pJzS2j1EHbh K3UMugKxOlEEPPtj1Xh3av3VhBke3ZM9XpIQTUZ2g0rVwVJXSweAUNbhYYtgAUgEMt2V ZF+eATBzBGDA1FPNLjzPdOdbT86tOpXoz9LcYvLrLQSaM1o4Ehvd0BdTwj2gztpef7HG FXPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=WxONRb8+; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id d29-20020a50f69d000000b004589d7e983esi9199050edn.596.2022.10.04.02.46.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 02:46:46 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=WxONRb8+; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D9E1385C41F for ; Tue, 4 Oct 2022 09:46:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D9E1385C41F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664876791; bh=ORE6MwU/WXwXXj2EPipdnDlfxgTJztsz5Pf/z3YDIA8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=WxONRb8+8Emkv22tKuyrnA+iZs1u6BajYfwaaKJcKQ8CoxMt41D4B4X+tQHEwZQ0s ZIfq2FPYfBSLDhX94upzsfO9Tz35NcUoMM4mgLd/qxQPq/Ss4bY2pgv0iXxVIBp+Qm du4PWx91z72b52GUzdVj/eAOqdqfkYPakLXPcZEk= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-sender-0.a4lg.com (mail-sender-0.a4lg.com [IPv6:2401:2500:203:30b:4000:6bfe:4757:0]) by sourceware.org (Postfix) with ESMTPS id 85F353858297; Tue, 4 Oct 2022 09:46:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 85F353858297 Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id C9F41300089; Tue, 4 Oct 2022 09:46:20 +0000 (UTC) To: Tsukasa OI , Nelson Chu , Kito Cheng , Palmer Dabbelt , Andrew Burgess , Jan Beulich , Andreas Schwab Subject: [PATCH v2 2/2] gdb/riscv: Partial support for instructions up to 176-bits Date: Tue, 4 Oct 2022 09:45:50 +0000 Message-Id: <4eb6e59ae2e790dbbf2bc92477edd281648d8814.1664876744.git.research_trasio@irq.a4lg.com> In-Reply-To: References: Mime-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, KAM_MANYTO, SPF_HELO_NONE, SPF_PASS, 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tsukasa OI via Binutils From: Tsukasa OI Reply-To: Tsukasa OI Cc: binutils@sourceware.org, gdb-patches@sourceware.org Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745749862306627435?= X-GMAIL-MSGID: =?utf-8?q?1745749862306627435?= Because riscv_insn_length started to support instructions up to 176-bit, we need to increase packet buffer size to 176-bit in size. Also, that would break an assumption in riscv_insn::decode so this commit fixes it. --- gdb/riscv-tdep.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c index 47d8f9e601b..433311e1024 100644 --- a/gdb/riscv-tdep.c +++ b/gdb/riscv-tdep.c @@ -1770,7 +1770,7 @@ riscv_insn::fetch_instruction (struct gdbarch *gdbarch, CORE_ADDR addr, int *len) { enum bfd_endian byte_order = gdbarch_byte_order_for_code (gdbarch); - gdb_byte buf[8]; + gdb_byte buf[RISCV_MAX_INSN_LEN]; int instlen, status; /* All insns are at least 16 bits. */ @@ -1933,9 +1933,10 @@ riscv_insn::decode (struct gdbarch *gdbarch, CORE_ADDR pc) } else { - /* This must be a 6 or 8 byte instruction, we don't currently decode - any of these, so just ignore it. */ - gdb_assert (m_length == 6 || m_length == 8); + /* 6 - 22 bytes instruction. If the length is larger than 8, we don't + have full instruction bits in ival. At least, such long instructions + are not defined yet, so just ignore it. */ + gdb_assert (m_length > 0 && m_length % 2 == 0); m_opcode = OTHER; } }