ld/pdb.c: uint16_t overflow in symbol size calculation
A uint16_t overflow vulnerability exists in ld/pdb.c's symbol size calculation and parsing functions, similar to a previously fixed issue.
This report highlights a uint16_t overflow vulnerability in ld/pdb.c within the calculate_symbols_size and parse_symbols functions. This issue is similar to a bug recently addressed by commit 147e60cae54. calculate_symbols_size lacks bounds checking entirely, and the existing check in parse_symbols fails when the length variable wraps around to 0. Proof-of-concept files and ASan output are available in the linked Bugzilla report.
- proposer
Reported a `uint16_t` overflow vulnerability in `ld/pdb.c` that was not caught by a previous fix.
“I've reported a bug in ld/pdb.c that was not caught by the recent commit 147e60cae54 ("Fix potential integer overflows in ld/pdb.c"): https://sourceware.org/bugzilla/show_bug.cgi?id=35058 The same uint16_t truncation pattern exists in calculate_symbols_size() and parse_symbols().”
- maintainer
Acknowledged the reported bug and its similarity to a previously fixed one, noting the specific failure condition of the existing check.
“The same uint16_t truncation pattern exists in calculate_symbols_size() and parse_symbols(). calculate_symbols_size() received no bounds check at all, and the "if (len > size)" check added to parse_symbols() does not trigger when len wraps to 0”
Technical Tradeoffs
- Fixes a potential integer overflow vulnerability that could lead to security issues.
- Requires careful analysis of integer types and bounds checking in symbol table processing.
In Details
This bug report for binutils concerns the ld linker's PDB (Program Database) file handling, specifically within ld/pdb.c. It identifies a uint16_t overflow vulnerability in functions responsible for calculating and parsing symbol table sizes. This vulnerability is a regression or an oversight from a prior commit intended to fix integer overflows. The issue arises from insufficient bounds checking and a condition where a length variable wrapping to zero bypasses existing checks, potentially leading to incorrect memory allocation or buffer overflows.
- ld
- The GNU linker, responsible for combining object files and libraries into an executable or library.
- pdb.c
- A source file likely related to handling Program Database (PDB) files, which store debugging information, particularly in environments like Windows.
- uint16_t
- An unsigned integer type that is exactly 16 bits wide.
- overflow
- A condition where an arithmetic operation attempts to create a numeric value that is too large to be represented within the allocated bits.
- Bugzilla
- An open-source bug tracking system used by many software projects, including Binutils, to manage bug reports and feature requests.
- ASan
- AddressSanitizer, a tool that detects memory errors such as buffer overflows.