binutils: od-xcoff: bound XCOFF loader section parsing
Hardens XCOFF parsing by bounding loader section parsing, preventing out-of-bounds reads in symbol, relocation, and string tables.
This patch enhances the robustness of the XCOFF dumper by adding bounds checking to the parsing of the .loader section. Previously, malformed loader sections could lead to out-of-bounds reads in various tables (symbol, relocation, import, string) due to unchecked entry counts and offsets. The changes validate section size, fit, and string table access, with improved error reporting and resource cleanup.
- proposer
Implements bounds checking for XCOFF `.loader` section parsing to prevent out-of-bounds reads.
“dump_xcoff32_loader parsed the .loader section without checking entry counts or string offsets against the section size. A malformed loader section could cause out-of-bounds reads in the symbol table, relocation table, import file list, or string table. Validate that the section is at least as large as the header. Report a too-short section with non_fatal so the diagnostic goes to stderr inste…”
In Details
This patch strengthens the od-xcoff dumper's resilience against malformed XCOFF files by validating the .loader section. It ensures that offsets, counts, and string lookups within this section are within bounds, preventing heap overflows and crashes. The changes include better error reporting using non_fatal and guarantee that allocated memory is freed on error paths, with new test cases covering various malformed input scenarios.
- XCOFF
- A file format used on IBM AIX systems, similar to COFF and ELF.
- .loader section
- A section in an XCOFF object file that contains information related to dynamic linking and loading.
- out-of-bounds read
- An attempt to access memory outside the allocated buffer, which can lead to data corruption or crashes.
- string table
- A section in an object file that stores string literals, often used for symbol names or other text data.