openwall / openwall/john

--fuzz leaks memory in formats with `psalt->dsalt.salt_alloc_needs_free = 1`

Open
#5,023 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

maintenance/cleanup
Dominant language
C
Stars
13.6k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

ASan reports leaks after --fuzzing format with dynamic salt allocation (#752).

I patched out most self tests in pkzip_fmt_plug.c, so only the last one is present. It is short and fuzzing finishes in 4 seconds. (Local paths are replaced by ....)

$ /usr/bin/time ./run/john --fuzz --format=pkzip
Fuzzing: PKZIP [32/64]...    Completed

All 1 formats passed fuzzing test!

=================================================================
==27080==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 386988 byte(s) in 271 object(s) allocated from:
    #0 0x7f8e3ac04518 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:95
    #1 0x56312e113172 in mem_calloc .../john/src/memory.c:107
    #2 0x56312e010988 in get_salt .../john/src/pkzip_fmt_plug.c:675
    #3 0x56312e0f9520 in ldr_load_pw_line .../john/src/loader.c:1045
    #4 0x56312e1991f6 in fuzz_test .../john/src/fuzz.c:586
    #5 0x56312e199760 in fuzz .../john/src/fuzz.c:689
    #6 0x56312e0ee3ab in john_run .../john/src/john.c:1672
    #7 0x56312e0ee3ab in main .../john/src/john.c:2082
    #8 0x7f8e3a16009a in __libc_start_main ../csu/libc-start.c:308

SUMMARY: AddressSanitizer: 386988 byte(s) leaked in 271 allocation(s).
Command exited with non-zero status 1
3.51user 0.87system 0:04.44elapsed 98%CPU (0avgtext+0avgdata 612640maxresident)k
8inputs+1440outputs (0major+187626minor)pagefaults 0swaps

Same thing happens with 7z. It can finish in ~50 seconds without commenting out self-tests. But 7z requires fix for #4971. (I am about to send PR with it.)

Both formats do not leak in regular runs (both --test and real attacks). So I guess that's a problem with fuzzer.

Both formats have the following setting for salts:

psalt->dsalt.salt_alloc_needs_free = 1;

I did not test formats with different variants of the setting.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the leak with an ASan build using ./run/john --fuzz --format=pkzip, then inspect src/fuzz.c and the get_salt path in src/pkzip_fmt_plug.c, with src/loader.c showing the call chain. Compare the fuzzer's salt lifecycle with regular --test or attack runs and verify that PKZIP and 7z no longer report leaks when fuzzing completes.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.