xtensa_insnbuf_from_chars buffer overflow checking
Fixes a buffer overflow in Xtensa instruction buffer handling in binutils and GDB.
This commit addresses a buffer overflow vulnerability in the xtensa_insnbuf_from_chars function used by binutils and GDB. The overflow occurs when processing zero-sized relocations (R_XTENSA_ASM_SIMPLIFY), which can be triggered by fuzzers. The fix modifies the function to return buffer size information, passes actual buffer lengths where it’s used, and checks return statuses to prevent overflows.
In Details
The xtensa_insnbuf_from_chars function in bfd/elf32-xtensa.c and gas/config/tc-xtensa.c was susceptible to buffer overflows when num_chars was zero. This could happen with R_XTENSA_ASM_SIMPLIFY relocations at section ends. The patch rectifies this by passing actual buffer lengths and checking return values, preventing out-of-bounds writes.
- R_XTENSA_ASM_SIMPLIFY
- A specific relocation type for the Xtensa architecture, used during assembly to simplify instruction generation. Its zero size in certain contexts caused issues.
- xtensa_insnbuf_from_chars
- A function within binutils and GDB that handles character-based input for Xtensa instruction buffers. It was found to have a buffer overflow vulnerability.
- Buffer overflow
- A condition where a program attempts to write data beyond the allocated buffer's boundaries, potentially corrupting adjacent memory or causing crashes.