Skip to content

AddressSanitizer: stack-buffer-overflow in jq_fuzz_execute (jv_string_vfmt)

Moderate
itchyny published GHSA-p7rr-28xf-3m5w May 21, 2025

Package

No package listed

Affected versions

master

Patched versions

None

Description

Summary

A heap-buffer-overflow was detected in function jv_string_vfmt in the jq_fuzz_execute harness from oss-fuzz.

Details

This crash happens on file jv.c, line 1456 void* p = malloc(sz);

I cloned the latest version of jq, compiled it using the build script from oss-fuzz, and fuzzed the jq_fuzz_execute harness.

ASAN output:

./jq_fuzz_execute testcase
=================================================================
==171939==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x603000000171 at pc 0x00000043c6b8 bp 0x7fffffff7330 sp 0x7fffffff6ab0
READ of size 2 at 0x603000000171 thread T0
    #0 0x43c6b7 in printf_common(void*, char const*, __va_list_tag*) /tmp/llvm/utils/release/final/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors_format.inc:553
    #1 0x504ab1 in jv_string_vfmt src/jv.c:1456
    #2 0x504ec7 in jv_string_fmt src/jv.c:1476
    #3 0x519676 in jv_get src/jv_aux.c:143
    #4 0x4dde20 in jq_next src/execute.c:699
    #5 0x4ce111 in LLVMFuzzerTestOneInput ./tests/jq_fuzz_execute.cpp:28
    #6 0x4cd69d in ExecuteFilesOnyByOne utils/aflpp_driver/aflpp_driver.c:255
    #7 0x4cd4a8 in LLVMFuzzerRunDriver ??:?
    #8 0x4cd068 in main utils/aflpp_driver/aflpp_driver.c:300
/usr/bin/addr2line: DWARF error: section .debug_info is larger than its filesize! (0x93f189 vs 0x531098)
    #9 0x7ffff7b3e082 in __libc_start_main ??:?
    #10 0x41e8ed in _start ??:?

0x603000000171 is located 0 bytes to the right of 17-byte region [0x603000000160,0x603000000171)
allocated by thread T0 here:
    #0 0x49958d in malloc /tmp/llvm/utils/release/final/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:145
    #1 0x5168f4 in jv_mem_alloc src/jv_alloc.c:141
    #2 0x5131fc in jvp_string_alloc src/jv.c:1067
    #3 0x4fc724 in jvp_string_empty_new src/jv.c:1109
    #4 0x4fc54f in jv_string_empty src/jv.c:1246
    #5 0x5e7dfd in binop_multiply src/builtin.c:350
    #6 0x5e25cf in constant_fold src/parser.y:216
    #7 0x5d97a1 in gen_binop src/parser.y:234
    #8 0x5c357a in yyparse src/parser.y:434
    #9 0x5e1224 in jq_parse src/parser.y:995
    #10 0x56d357 in load_program src/linker.c:413
    #11 0x4eb183 in jq_compile_args src/execute.c:1245
    #12 0x4ecd03 in jq_compile src/execute.c:1262
    #13 0x4cdd32 in LLVMFuzzerTestOneInput ./tests/jq_fuzz_execute.cpp:21
    #14 0x4cd69d in ExecuteFilesOnyByOne utils/aflpp_driver/aflpp_driver.c:255

SUMMARY: AddressSanitizer: heap-buffer-overflow /tmp/llvm/utils/release/final/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors_format.inc:553 in printf_common(void*, char const*, __va_list_tag*)
Shadow bytes around the buggy address:
  0x0c067fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c067fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c067fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c067fff8000: fa fa 00 00 00 02 fa fa 00 00 06 fa fa fa fd fd
  0x0c067fff8010: fd fd fa fa 00 00 00 04 fa fa fd fd fd fa fa fa
=>0x0c067fff8020: fd fd fd fa fa fa fd fd fd fa fa fa 00 00[01]fa
  0x0c067fff8030: fa fa 00 00 06 fa fa fa 00 00 04 fa fa fa 00 00
  0x0c067fff8040: 06 fa fa fa 00 00 04 fa fa fa fd fd fd fa fa fa
  0x0c067fff8050: fd fd fd fa fa fa fd fd fd fa fa fa fd fd fd fd
  0x0c067fff8060: fa fa fd fd fd fa fa fa fd fd fd fd fa fa fd fd
  0x0c067fff8070: fd fd fa fa fd fd fd fd fa fa fd fd fd fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==171939==ABORTING

Environment info:
uname -a output: Linux ThinkPad 5.15.0-107-generic #117 SMP Tue Apr 30 10:35:57 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Clang version: 12.0.1

PoC

The testcase is contained in the following zip archive:
testcase.zip

Impact

Heap-buffer-overflow

Severity

Moderate

CVE ID

CVE-2025-48060

Weaknesses

No CWEs

Credits