Skip to content

malformed e_phnum value leads to OOB read #36

Description

@echel0nn

Describe the Bug

A bad ELF File which can lead elf_segment_iterator_next() to access out of bound memory or memory leak due to malformed e_phnum value.

To Reproduce

  1. Simply run examples/elfparse with 1.bin, 2.bin, 3.bin

To Reproduce afl-fuzz:

Note: Most of them are just my laziness, usually I just copy/paste the environment values.

  1. CC=afl-cc CXX=afl-c++ CFLAGS="-g -flto=auto" CXXFLAGS=-g CPPFLAGS=-g PKG_CONFIG_PATH=./build ./configure --prefix=$PWD deleted dl from required packages
  2. CC=afl-cc CXX=afl-c++ CFLAGS="-g -flto=auto" CXXFLAGS=-g CPPFLAGS=-g AR=llvm-ar make -j24 all
  3. INSTRUMENTATIONS
export AFL_LLVM_CMPLOG=1 
export AFL_LLVM_LAF_ALL=1
export AFL_USE_CFISAN=1 

Expected Behaviour

Parse and Detect the e_phnum anomaly, refuse to allocate memory for non-existent segments and exit gracefully.

Environment

  • System and Version: Linux 6.2.10-zen1-1-zen x86_64 GNU/Linux, clang version 15.0.7
  • Target file: examples/elfparse

Additional Comments

Found more bugs with the dead_bytes.bin binary that is produced by libgolf.h as one and only unique seed but they need more time to triage.
screenshot-2023-04-11-04-25-50

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions