#6038·john

[SECURITY] Null-pointer dereference at src/mkvlib.c:44 from a zero-size auto-level allocation

Author: shootduckCreated Sep 21, 2026Updated Sep 21, 2026
Labelsbugmaintenance/cleanupdupe

Vulnerability description

The genmkvpwd command-line parser assigns the result of atoi directly to an unsigned int. Supplying -1 as max_len converts -1 to 4,294,967,295. In the automatic-level branch, the allocation at src/genmkvpwd.c:253 is performed before any bound is applied to max_len.

c
if (argc > 3)
    max_len = atoi(argv[3]);

if (max_lvl == 0) {
    for (max_lvl = 100; max_lvl <= MAX_MKV_LVL; max_lvl++) {
        nbparts = mem_alloc(256 * (max_lvl + 1) *
                            sizeof(long long) * (max_len + 1));
        nb_parts(0, 0, 0, max_lvl, max_len);
    }
}

The expression max_len + 1 is evaluated as 32-bit unsigned arithmetic and wraps from 0xffffffff to zero. The requested allocation size is therefore zero. mem_alloc(0) deliberately returns NULL, but nb_parts immediately reads nbparts[0] at src/mkvlib.c:44.

This is a null-pointer read caused by integer-wrap-induced zero-size allocation, resulting in a deterministic denial of service. It is not an AddressSanitizer heap-buffer-overflow classification: the invalid address is the NULL page.

Version and commit

John the Ripper 1.9.0-jumbo-1+bleeding, commit 9a336d800a091bec9650c29282485145f31c9ffc (built version string: 1.9.0-jumbo-1+bleeding-9a336d800a).

Environment

  • Ubuntu 24.04.4 LTS; Linux 6.8.0-136-generic; x86_64.

  • GCC 13.3.0, glibc 2.39, and GCC AddressSanitizer.

  • The binary was configured with --without-openssl --enable-asan, debug information, and frame pointers.

Steps to reproduce

  1. On Ubuntu, install the build prerequisites:

    bash
    sudo apt-get update
    sudo apt-get install -y build-essential git perl
  2. Check out the vulnerable revision and set POC_STATS to the absolute path of the included stats artifact:

    bash
    export JTR=$PWD/john
    export POC_STATS=/absolute/path/to/stats
    git clone https://github.com/openwall/john.git "$JTR"
    git -C "$JTR" checkout 9a336d800a091bec9650c29282485145f31c9ffc
  3. Build genmkvpwd with AddressSanitizer:

    bash
    cd "$JTR/src"
    ./configure --quiet --without-openssl --enable-asan CC=gcc \
      CFLAGS='-O0 -g -fno-omit-frame-pointer' \
      CFLAGS_EXTRA='-O0 -g -fno-omit-frame-pointer' \
      LDFLAGS='-fsanitize=address'
    make -j"$(nproc)"
  4. Run the PoC. The process terminates on a NULL read in nb_parts:

    bash
    cd "$JTR/run"
    ./genmkvpwd "$POC_STATS" 0 -1 2> sanitizer_report.txt

Sanitizer report

The following is the complete, unmodified report included as sanitizer_report.txt.

AddressSanitizer:DEADLYSIGNAL
=================================================================
==888454==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x5ffc8f009cb8 bp 0x7ffc5339a380 sp 0x7ffc5339a350 T0)
==888454==The signal is caused by a READ memory access.
==888454==Hint: address points to the zero page.
    #0 0x5ffc8f009cb8 in nb_parts /home/shootduck/hotracer-experiments/0-day/hotracer/pilot/genmkvpwd/2026-08-01-1.9.0-jumbo-1+bleeding-9a336d8/john/build-asan/src/mkvlib.c:44
    #1 0x5ffc8f008de5 in main /home/shootduck/hotracer-experiments/0-day/hotracer/pilot/genmkvpwd/2026-08-01-1.9.0-jumbo-1+bleeding-9a336d8/john/build-asan/src/genmkvpwd.c:256
    #2 0x73e67442a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #3 0x73e67442a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #4 0x5ffc8f006784 in _start (/home/shootduck/hotracer-experiments/0-day/hotracer/pilot/genmkvpwd/2026-08-01-1.9.0-jumbo-1+bleeding-9a336d8/john/build-asan/run/genmkvpwd+0x4784) (BuildId: 4875d0d0571be6b5aca6c0dbdb99f1729b7a84ad)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/shootduck/hotracer-experiments/0-day/hotracer/pilot/genmkvpwd/2026-08-01-1.9.0-jumbo-1+bleeding-9a336d8/john/build-asan/src/mkvlib.c:44 in nb_parts
==888454==ABORTING

Potential fix

Normalize both Markov limits before choosing an allocation branch. The program already defines MAX_MKV_LVL and MAX_MKV_LEN, and src/mkv.c applies equivalent bounds. This patch makes a negative value converted to unsigned clamp to MAX_MKV_LEN before max_len + 1 is evaluated.

I applied this diff to a fresh checkout of the vulnerable commit, rebuilt it with the ASan command above, and reran this invocation and the equivalent main-path invocation. Both completed without an AddressSanitizer diagnostic.

diff
diff --git a/src/genmkvpwd.c b/src/genmkvpwd.c
index de62d03..2d19662 100644
--- a/src/genmkvpwd.c
+++ b/src/genmkvpwd.c
@@ -224,6 +224,16 @@ int main(int argc, char * * argv)
 		end = atoll(argv[5]);
 
 	init_probatables(argv[1]);
+	if (max_lvl > MAX_MKV_LVL) {
+		fprintf(stderr, "Warning: Level = %u is too large (max = %d)\n",
+		        max_lvl, MAX_MKV_LVL);
+		max_lvl = MAX_MKV_LVL;
+	}
+	if (max_len > MAX_MKV_LEN) {
+		fprintf(stderr, "Warning: Maxlen = %u is too large (max = %d)\n",
+		        max_len, MAX_MKV_LEN);
+		max_len = MAX_MKV_LEN;
+	}
 
 	if (max_len == 0)
 	{
@@ -266,11 +276,6 @@ int main(int argc, char * * argv)
 		}
 		goto fin;
 	}
-	if (max_lvl>MAX_MKV_LVL) {
-		fprintf(stderr, "Warning: Level = %d is too large (max = %d)\n", max_lvl, MAX_MKV_LVL);
-		max_lvl = MAX_MKV_LVL;
-	}
-
 	nbparts = mem_alloc(256*(max_lvl+1)*sizeof(long long)*(max_len+1));
 	fprintf(stderr, "allocated %lu KB for nbparts\n", (unsigned long)(256UL*(max_lvl+1)*(max_len+1)*sizeof(long long)/1024));
 	memset(nbparts, 0, 256*(max_lvl+1)*(max_len+1)*sizeof(long long));

Artifacts

The PoC and the sanitizer report are packaged into this ZIP file.

artifacts.zip