In GNU Binutils 2.31.1, there is a use-after-free in the error function in elfcomm.c when called from the process_archive function in readelf.c via a crafted ELF file.
GNU Binutils 2.31.1 is vulnerable to a use-after-free condition, allowing attackers to potentially execute arbitrary code. This vulnerability, triggered by a crafted ELF file, can lead to system compromise and data breaches. Exploitation requires the victim to process a malicious ELF file, making it a potential target for supply-chain attacks or targeted campaigns.
Step 1: Payload Delivery: The attacker crafts a malicious ELF file containing specially crafted archive members.
Step 2: File Processing: The victim uses readelf (from GNU Binutils 2.31.1) to process the malicious ELF file.
Step 3: Triggering the Vulnerability: The process_archive function within readelf.c encounters the crafted archive members.
Step 4: Memory Corruption: Due to a flaw in memory management, a memory region is freed prematurely.
Step 5: Use-After-Free: The error function in elfcomm.c is called, attempting to access the freed memory.
Step 6: Code Execution (Potential): This access can lead to a crash or, with careful exploitation, arbitrary code execution, allowing the attacker to control the victim's system.
The vulnerability lies within the GNU Binutils package, specifically in the readelf utility. The error function in elfcomm.c is called from process_archive in readelf.c. The root cause is a use-after-free condition. The process_archive function, when handling a crafted ELF file, can trigger a scenario where memory is freed prematurely. Subsequently, the error function attempts to access the freed memory, leading to the vulnerability. This occurs due to improper memory management when processing archive members within the ELF file, potentially related to how error handling interacts with the freeing of allocated data structures. The crafted ELF file exploits the logic within process_archive to trigger the premature freeing and subsequent use of the freed memory by the error function.