| Message ID | 89612fe01d902007bf84a7dfb0df5f85d5c166e4.1664873933.git.research_trasio@irq.a4lg.com |
|---|---|
| State | Superseded |
| Headers |
Return-Path: <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 06ECE385415E for <patchwork@sourceware.org>; Tue, 4 Oct 2022 09:00:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 06ECE385415E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664874018; bh=10RJpob7TsEpqZgz/da2hq7jdcBrovdJT3P2jfK5qUs=; 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=c/vFjky21FZHvvYfHV047xztqwbsnxjcNR/C0gvXRAigdfYNCIkkJnPa49VJlvF81 8xiM26zJlb2fJCvH4MqfGCx5z2IXC3yrxy+JBacPB3tbe1K/2Lo2EiJkI5mZQ1mbUm yvPBHTGIUZEhTw9S/w7cviL5fBo45ognh0u/zTzw= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-sender-0.a4lg.com (mail-sender.a4lg.com [153.120.152.154]) by sourceware.org (Postfix) with ESMTPS id 03A53385C335; Tue, 4 Oct 2022 08:59:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 03A53385C335 Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id 4294A300089; Tue, 4 Oct 2022 08:59:42 +0000 (UTC) To: Tsukasa OI <research_trasio@irq.a4lg.com>, Nelson Chu <nelson@rivosinc.com>, Kito Cheng <kito.cheng@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Andrew Burgess <aburgess@redhat.com>, Jan Beulich <jbeulich@suse.com> Subject: [PATCH 2/2] gdb/riscv: Fix buffer overflow on riscv_insn::fetch_instruction Date: Tue, 4 Oct 2022 08:59:08 +0000 Message-Id: <89612fe01d902007bf84a7dfb0df5f85d5c166e4.1664873933.git.research_trasio@irq.a4lg.com> In-Reply-To: <cover.1664873933.git.research_trasio@irq.a4lg.com> References: <cover.1664873933.git.research_trasio@irq.a4lg.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.0 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: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> From: Tsukasa OI via Gdb-patches <gdb-patches@sourceware.org> Reply-To: Tsukasa OI <research_trasio@irq.a4lg.com> Cc: binutils@sourceware.org, gdb-patches@sourceware.org Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> |
| Series |
RISC-V: Fix buffer overflow after long instruction support
|
|
Commit Message
Tsukasa OI
Oct. 4, 2022, 8:59 a.m. UTC
Because riscv_insn_length started to support instructions up to 176-bit, we need to increase packet buffer size to 176-bit in size. Note that this change will make the result of riscv_insn::fetch_instruction partial when the instruction is longer than 64-bits. To really support instructions longer than 64-bit, we need something more. --- gdb/riscv-tdep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Okt 04 2022, Tsukasa OI via Gdb-patches wrote: > diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c > index 47d8f9e601b..99307bd2de1 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[22]; Can the magic number be derived from something else so that is adapts automatically?
On 2022/10/04 18:04, Andreas Schwab wrote: > On Okt 04 2022, Tsukasa OI via Gdb-patches wrote: > >> diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c >> index 47d8f9e601b..99307bd2de1 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[22]; > > Can the magic number be derived from something else so that is adapts > automatically? > Well... That's technically possible but it will make something like... 8 + 2 + 2 * ((1 << 3) - 1 - 1) and I don't think that would improve something (it heavily depends on the encoding magic [no relevant constants are defined so far] so it's just "from magic to magic"). Defining RISCV_MAX_INSN_LEN might be a slightly better solution (still, content of RISCV_MAX_INSN_LEN will be a magic number). Thanks, Tsukasa
On Okt 04 2022, Tsukasa OI wrote: > That's technically possible but it will make something like... > 8 + 2 + 2 * ((1 << 3) - 1 - 1) That's still a magic number that doesn't adapt. > Defining RISCV_MAX_INSN_LEN might be a slightly better solution (still, > content of RISCV_MAX_INSN_LEN will be a magic number). If that number is then used as the base for the other dependencies, it's a win.
On 2022/10/04 18:25, Andreas Schwab wrote: > On Okt 04 2022, Tsukasa OI wrote: > >> That's technically possible but it will make something like... >> 8 + 2 + 2 * ((1 << 3) - 1 - 1) > > That's still a magic number that doesn't adapt. Exactly. I could not find any constants to depend to. If we define "currently" magic number (22) as RISCV_MAX_INSN_LEN, at least we can share that constant between Binutils and GDB. > >> Defining RISCV_MAX_INSN_LEN might be a slightly better solution (still, >> content of RISCV_MAX_INSN_LEN will be a magic number). > > If that number is then used as the base for the other dependencies, it's > a win. >
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c index 47d8f9e601b..99307bd2de1 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[22]; int instlen, status; /* All insns are at least 16 bits. */