[GH-ISSUE #1230] Loader memory leak #774

Closed
opened 2026-10-14 03:23:28 +07:00 by bsakaguchi · 7 comments
Owner

Originally created by @loverszhaokai on GitHub (Apr 27, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1230

Originally assigned to: @loverszhaokai on GitHub.

Maybe this is not a bug. If it does not a bug, do you have any idea to avoid this bug?
#1. Prepare

1.1 content of 7z_fmt

$7z$0$19$0$1122$8$d1f50227759415890000000000000000$1412385885$112$112$5e5b8b734adf52a64c541a5a5369023d7cccb78bd910c0092535dfb013a5df84ac692c5311d2e7bbdc580f5b867f7b5dd43830f7b4f37e41c7277e228fb92a6dd854a31646ad117654182253706dae0c069d3f4ce46121d52b6f20741a0bb39fc61113ce14d22f9184adafd6b5333133

1.2 compile with asan

$ export ASAN_OPTIONS='abort_on_error=1'
$ CC=clang AFL_USE_ASAN=1 AFL_HARDEN=1 ./configure --enable-asan && make -sj8
#2. Reproduce

$ echo garbage > test.pw
$ ./john 7z_fmt --loopback=test.pw --max-run-time=1
Warning: detected hash type "7z", but the string is also recognized as "7z-opencl"
Use the "--format=7z-opencl" option to force loading these as that type instead
Loaded 1 password hash (7z, 7-Zip [SHA256 AES 32/64])
Note: This format may emit false positives, so it will keep trying even after
finding a possible candidate.
Press 'q' or Ctrl-C to abort, almost any other key for status
0g 0:00:00:00 0g/s 8.433p/s 8.433c/s 8.433C/s GARbage
Session stopped (max run-time reached)

==8582==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 524288 byte(s) in 1 object(s) allocated from:
#0 0x4b5530 in __interceptor_malloc /home/kai/workspace/llvm-3.6.0.src/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:40
#1 0x8fa6e8 in mem_alloc_func /home/kai/workspace/john_jumbo/JohnTheRipper_fuzz_options/src/memory.c:89:8
#2 0x8d0f4f in ldr_init_database /home/kai/workspace/john_jumbo/JohnTheRipper_fuzz_options/src/loader.c:161:22
#3 0x8cb90e in john_load /home/kai/workspace/john_jumbo/JohnTheRipper_fuzz_options/src/john.c:1074:3
#4 0x8c1e9c in john_init /home/kai/workspace/john_jumbo/JohnTheRipper_fuzz_options/src/john.c:1249:2
#5 0x8c0d17 in main /home/kai/workspace/john_jumbo/JohnTheRipper_fuzz_options/src/john.c:1682:2
#6 0x7fd2b7d22d1c in __libc_start_main (/lib64/libc.so.6+0x1ed1c)

SUMMARY: AddressSanitizer: 524288 byte(s) leaked in 1 allocation(s).

Originally created by @loverszhaokai on GitHub (Apr 27, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1230 Originally assigned to: @loverszhaokai on GitHub. Maybe this is not a bug. If it does not a bug, do you have any idea to avoid this bug? #1. Prepare ## 1.1 content of 7z_fmt $7z$0$19$0$1122$8$d1f50227759415890000000000000000$1412385885$112$112$5e5b8b734adf52a64c541a5a5369023d7cccb78bd910c0092535dfb013a5df84ac692c5311d2e7bbdc580f5b867f7b5dd43830f7b4f37e41c7277e228fb92a6dd854a31646ad117654182253706dae0c069d3f4ce46121d52b6f20741a0bb39fc61113ce14d22f9184adafd6b5333133 ## 1.2 compile with asan $ export ASAN_OPTIONS='abort_on_error=1' $ CC=clang AFL_USE_ASAN=1 AFL_HARDEN=1 ./configure --enable-asan && make -sj8 #2. Reproduce $ echo garbage > test.pw $ ./john 7z_fmt --loopback=test.pw --max-run-time=1 Warning: detected hash type "7z", but the string is also recognized as "7z-opencl" Use the "--format=7z-opencl" option to force loading these as that type instead Loaded 1 password hash (7z, 7-Zip [SHA256 AES 32/64]) Note: This format may emit false positives, so it will keep trying even after finding a possible candidate. Press 'q' or Ctrl-C to abort, almost any other key for status 0g 0:00:00:00 0g/s 8.433p/s 8.433c/s 8.433C/s GARbage Session stopped (max run-time reached) # ==8582==ERROR: LeakSanitizer: detected memory leaks Direct leak of 524288 byte(s) in 1 object(s) allocated from: #0 0x4b5530 in __interceptor_malloc /home/kai/workspace/llvm-3.6.0.src/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:40 #1 0x8fa6e8 in mem_alloc_func /home/kai/workspace/john_jumbo/JohnTheRipper_fuzz_options/src/memory.c:89:8 #2 0x8d0f4f in ldr_init_database /home/kai/workspace/john_jumbo/JohnTheRipper_fuzz_options/src/loader.c:161:22 #3 0x8cb90e in john_load /home/kai/workspace/john_jumbo/JohnTheRipper_fuzz_options/src/john.c:1074:3 #4 0x8c1e9c in john_init /home/kai/workspace/john_jumbo/JohnTheRipper_fuzz_options/src/john.c:1249:2 #5 0x8c0d17 in main /home/kai/workspace/john_jumbo/JohnTheRipper_fuzz_options/src/john.c:1682:2 #6 0x7fd2b7d22d1c in __libc_start_main (/lib64/libc.so.6+0x1ed1c) SUMMARY: AddressSanitizer: 524288 byte(s) leaked in 1 allocation(s).
bsakaguchi 2026-10-14 03:23:28 +07:00
Author
Owner

@frank-dittrich commented on GitHub (Apr 27, 2015):

Looks like for some reason the MEM_FREE(database.cracked_hash); in john.c, line 1512 is not processed when the --max-tun-time limit is reached.
Did you disable john_done() for your fuzzing?

<!-- gh-comment-id:96601343 --> @frank-dittrich commented on GitHub (Apr 27, 2015): Looks like for some reason the `MEM_FREE(database.cracked_hash);` in john.c, line 1512 is not processed when the --max-tun-time limit is reached. Did you disable john_done() for your fuzzing?
Author
Owner

@loverszhaokai commented on GitHub (Apr 27, 2015):

@frank-dittrich

Looks like for some reason the MEM_FREE(database.cracked_hash); in john.c, line 1512 is not processed when the --max-tun-time limit is reached.

$ ./john 7z_fmt --loopback=test.pw

This command can also reproduce this bug, but you should press 'q' or Ctrl-C to abort.

Did you disable john_done() for your fuzzing?

No

<!-- gh-comment-id:96602661 --> @loverszhaokai commented on GitHub (Apr 27, 2015): @frank-dittrich > Looks like for some reason the MEM_FREE(database.cracked_hash); in john.c, line 1512 is not processed when the --max-tun-time limit is reached. $ ./john 7z_fmt --loopback=test.pw This command can also reproduce this bug, but you should press 'q' or Ctrl-C to abort. > Did you disable john_done() for your fuzzing? No
Author
Owner

@frank-dittrich commented on GitHub (Apr 27, 2015):

Yes, I can see the memory leek with memdbg as well:

$ make -s distclean; ./configure --enable-memdbg && make -s clean && make -s -j 8
[...]
$ cd ../run
$ ./john --list=format-tests --format=7z |cut -f 3 | head -n 1 > 7z.hash
$ echo x:garbage > test.pw
$ ./john 7z.hash --loopback=test.pw 
Loaded 1 password hash (7z, 7-Zip [SHA256 AES 32/64])
Will run 4 OpenMP threads
Note: This format may emit false positives, so it will keep trying even after
finding a possible candidate.
Press 'q' or Ctrl-C to abort, almost any other key for status
0g 0:00:00:02 DONE (2015-04-27 12:54) 0g/s 60.66p/s 60.66c/s 60.66C/s GARBagE..GARBAGE
Session completed

------------------------------
MEMDBG: allocation information (display):
   current normal alloc mem (leaks)524288  max normal mem allocated: 1283152
   current 'tiny' alloc mem (leaks)0  max  tiny  mem allocated: 2651714

Index : alloc# :   Size : File(Line)  [first 20 bytes, or size of bytes]
0     : 96     : 524288 : loader.c(162)  ....................
At Program Exit
MemDbg_Validate level 0 checking Passed

I used x:garbage instad of garbage, because --loopback is supposed to process a .pot file and split the lines into hashes and passwords, just using the passwords.
But that apparently didn't help either.

<!-- gh-comment-id:96609670 --> @frank-dittrich commented on GitHub (Apr 27, 2015): Yes, I can see the memory leek with memdbg as well: ``` $ make -s distclean; ./configure --enable-memdbg && make -s clean && make -s -j 8 [...] $ cd ../run $ ./john --list=format-tests --format=7z |cut -f 3 | head -n 1 > 7z.hash $ echo x:garbage > test.pw $ ./john 7z.hash --loopback=test.pw Loaded 1 password hash (7z, 7-Zip [SHA256 AES 32/64]) Will run 4 OpenMP threads Note: This format may emit false positives, so it will keep trying even after finding a possible candidate. Press 'q' or Ctrl-C to abort, almost any other key for status 0g 0:00:00:02 DONE (2015-04-27 12:54) 0g/s 60.66p/s 60.66c/s 60.66C/s GARBagE..GARBAGE Session completed ------------------------------ MEMDBG: allocation information (display): current normal alloc mem (leaks)524288 max normal mem allocated: 1283152 current 'tiny' alloc mem (leaks)0 max tiny mem allocated: 2651714 Index : alloc# : Size : File(Line) [first 20 bytes, or size of bytes] 0 : 96 : 524288 : loader.c(162) .................... At Program Exit MemDbg_Validate level 0 checking Passed ``` I used `x:garbage` instad of `garbage`, because --loopback is supposed to process a .pot file and split the lines into hashes and passwords, just using the passwords. But that apparently didn't help either.
Author
Owner

@frank-dittrich commented on GitHub (Apr 27, 2015):

With other salted formats, the error can be reproduced, with saltless formars, it can't.

<!-- gh-comment-id:96610032 --> @frank-dittrich commented on GitHub (Apr 27, 2015): With other salted formats, the error can be reproduced, with saltless formars, it can't.
Author
Owner

@frank-dittrich commented on GitHub (Apr 27, 2015):

BTW, with --enable-memdbg, I see the leaks even if I don't press <ctrl>-c to abort, see the Session completed output.

<!-- gh-comment-id:96610674 --> @frank-dittrich commented on GitHub (Apr 27, 2015): BTW, with --enable-memdbg, I see the leaks even if I don't press `<ctrl>-c` to abort, see the `Session completed` output.
Author
Owner

@magnumripper commented on GitHub (Apr 28, 2015):

Maybe this is not a bug. If it does not a bug, do you have any idea to avoid this bug?

I think Solar doesn't consider it a memory leak since it's only allocated once. He said on john-dev at some time (long ago, and regarding some other but similar case) that it's freed by the OS at program exit, so why bother?

But we have fixed some other similar cases in Jumbo, simply to make it easier finding real leaks (that actually grow).

In this case, I think we'd need to introduce a ldr_done() to address it.

<!-- gh-comment-id:97228730 --> @magnumripper commented on GitHub (Apr 28, 2015): > Maybe this is not a bug. If it does not a bug, do you have any idea to avoid this bug? I think Solar doesn't consider it a memory leak since it's only allocated once. He said on john-dev at some time (long ago, and regarding some other but similar case) that it's freed by the OS at program exit, so why bother? But we have fixed some other similar cases in Jumbo, simply to make it easier finding real leaks (that actually grow). In this case, I think we'd need to introduce a `ldr_done()` to address it.
Author
Owner

@loverszhaokai commented on GitHub (May 3, 2015):

@frank-dittrich @magnumripper

There is really a memory leak, with the command ./john 7z_fmt --loopback=test.pw --max-run-time=1, the ldr_init_database() function is called twice. And we only free the database but not the loop_db.

static void john_load(void)
{
    ...
    ldr_init_database(&database, &options.loader);
    ...
    if (options.flags & FLG_LOOPBACK_CHK &&
        database.format != &fmt_LM) {
        struct db_main loop_db;
        ...
        ldr_init_database(&loop_db, &options.loader);
        ...
    }
    ....
}
<!-- gh-comment-id:98485499 --> @loverszhaokai commented on GitHub (May 3, 2015): @frank-dittrich @magnumripper There is really a memory leak, with the command `./john 7z_fmt --loopback=test.pw --max-run-time=1`, the `ldr_init_database()` function is called twice. And we only free the database but not the loop_db. ``` static void john_load(void) { ... ldr_init_database(&database, &options.loader); ... if (options.flags & FLG_LOOPBACK_CHK && database.format != &fmt_LM) { struct db_main loop_db; ... ldr_init_database(&loop_db, &options.loader); ... } .... } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#774
No description provided.