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;