[PATCH 0/2] RISC-V: Fix buffer overflow after long instruction support

Jan Beulich jbeulich@suse.com
Tue Oct 4 09:07:39 GMT 2022


On 04.10.2022 10:59, Tsukasa OI wrote:
> After commit bb996692bd9 "RISC-V/gas: allow generating up to 176-bit
> instructions with .insn", I started to see some crashes while running
> "make check-gas".

Hmm, I'm puzzled why things worked correctly for me. The extra size needed
is quite significant, so chances should be rather slim for things to work
correctly.

> The cause was simple.  Some functions depended on the fact that maximum
> length returned by riscv_insn_length is 8.  But since the commit above
> increased that upper limit from 64-bits (8 bytes) to 176-bits (22 bytes),
> we need to increase two buffer sizes to avoid crashes.
> 
> But note that this change doesn't really support over 64-bit instructions.
> It can be said on riscv_insn::fetch_instruction because it now may return
> only a part of instruction.
> Instead of merging this, reverting that commit (for now) might be an option.

Please let's try to avoid reverting - the ability to emit wide instructions
via .insn helps testsuites beyond binutils' / gas'es.

In any event - thanks for the quick fixing of the issue. I wonder though
whether a connection (at least by way of comments) should be established so
that the same oversight won't happen again (e.g. once the spec spells out
how even wider insns would be encoded).

Jan


More information about the Binutils mailing list