fuzz: unpoison argc/argv in LLVMFuzzerInitialize under MSan #37047

pull fanquake wants to merge 1 commits into bitcoin:master from fanquake:fuzz_msan_unpoison_argv changing 1 files +17 −0
  1. fanquake commented at 2:35 PM on December 2, 2026: member

    libFuzzer's main() is not MSan-instrumented, which causes false positives.This causes a false-positive use-of-uninitialized-value in SetArgs.

    This has been applied downstream in oss-fuzz since https://github.com/google/oss-fuzz/pull/16707. Do we want to apply it here, given the issue could be seen outside of oss-fuzz?

  2. DrahtBot added the label Fuzzing on Dec 2, 2026
  3. fanquake commented at 2:35 PM on December 2, 2026: member
  4. DrahtBot commented at 2:35 PM on December 2, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK maflcko

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #35911 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35911.svg"></sub> (Warn on and add missing [[noreturn]] by fanquake)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. DrahtBot added the label CI failed on Dec 2, 2026
  6. DrahtBot commented at 3:41 PM on December 2, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task iwyu: https://github.com/bitcoin/bitcoin/actions/runs/46904405104/job/143542505286</sub> <sub>LLM reason (✨ experimental): intermittent_network: Docker image retrieval failed because mirror.gcr.io returned HTTP 429 after exceeding its Artifact Registry request quota.</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • Intermittent network issues can occur; re-run CI for now, and report the issue if they keep happening.

    • A functional or integration test failure may be intermittent or unrelated to this pull request. If no dedicated issue thread exists, create a new one to track it.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  7. DrahtBot removed the label CI failed on Dec 2, 2026
  8. maflcko commented at 5:51 PM on December 2, 2026: member

    thx. Seems fine. Could revert #33666 to get back the 60s of empty fuzzing?

    Though, ideally this is fixed upstream some time in the future in llvm in https://github.com/llvm/llvm-project/blob/932dda8e34ae3e214ea12f75d7f6cf95c2704a3f/compiler-rt/lib/fuzzer/FuzzerDriver.cpp#L658, as this affects all projects where the main frame collides with poisoned stack bytes from early temp C++ static init stuff.

  9. fuzz: unpoison argc/argv in LLVMFuzzerInitialize under MSan
    libFuzzer's main() is not MSan-instrumented, so the shadow of the stack
    slots holding argc/argv may be stale, left over from global constructors
    that ran at the same stack depth. This causes a false-positive
    use-of-uninitialized-value in SetArgs.
    e442658414
  10. fanquake force-pushed on Dec 3, 2026
  11. fanquake marked this as ready for review on Dec 3, 2026
  12. fanquake commented at 10:20 AM on December 3, 2026: member

    Could revert #33666 to get back the 60s of empty fuzzing?

    Thanks. Pulled in a reversion.

  13. maflcko commented at 10:23 AM on December 3, 2026: member

    thx. Though there is now a linker error.

    review ACK 46a9b9ae9b3c11a44e4a3c34b81ecebbc11ddbb6 🔷

    <details><summary>Show signature</summary>

    Signature:

    untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
    RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
    trusted comment: review ACK 46a9b9ae9b3c11a44e4a3c34b81ecebbc11ddbb6 🔷
    eDBOnxid4PHKZEkVAD+p+g45+H1p/1o0nrcqySIooWNas51eVMxaiFKBkjY1nKaiHq20nN9ABPu6qj7j0LOCBw==
    

    </details>

  14. fanquake commented at 10:24 AM on December 3, 2026: member

    Yea, we can't do this cause the apt libfuzzer is built against libstdc++, which we've seen before. I'll drop the revert for now.

  15. maflcko commented at 10:24 AM on December 3, 2026: member

    ok:

    review ACK e4426584148c3bd9dc0c0db2f1130eeafa788e50 🤜

    <details><summary>Show signature</summary>

    Signature:

    untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
    RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
    trusted comment: review ACK e4426584148c3bd9dc0c0db2f1130eeafa788e50 🤜
    k/3UBqyrFD/foIyo+xcv9oqtEpp9FHtiMV5yVFaZ+FFEGdluSAIa4USmR1DyVrBxyzhE8oCmGGX+b/8NE7laDg==
    

    </details>

  16. fanquake force-pushed on Dec 3, 2026
  17. fanquake commented at 10:25 AM on December 3, 2026: member
  18. maflcko commented at 10:26 AM on December 3, 2026: member

    the apt libfuzzer is built against libstdc++

    I guess we could build libfuzzer against libc++, like tsan, but I am not sure how tedious this is and whether this is worth it.

    <!-- diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh index a0beb72..189c2f6 100755 --- a/ci/test/00_setup_env_native_fuzz_with_msan.sh +++ b/ci/test/00_setup_env_native_fuzz_with_msan.sh @@ -24,3 +24,3 @@ printf -v BITCOIN_CONFIG "%q " \ -DBUILD_FOR_FUZZING=ON \ - -DSANITIZERS=memory \ + -DSANITIZERS=fuzzer,memory \ -DAPPEND_CPPFLAGS="-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE -U_FORTIFY_SOURCE" `# _FORTIFY_SOURCE is not compatible with MSAN` @@ -28,2 +28,3 @@ export BITCOIN_CONFIG export USE_INSTRUMENTED_LIBCPP="MemoryWithOrigins" +export BUILD_LIBFUZZER_WITH_LIBCXX=1 export RUN_UNIT_TESTS=false diff --git a/ci/test/01_base_install.sh b/ci/test/01_base_install.sh index 3e2a120..3b5b4df 100755 --- a/ci/test/01_base_install.sh +++ b/ci/test/01_base_install.sh @@ -68,3 +68,3 @@ fi -if [[ -n "${USE_INSTRUMENTED_LIBCPP}" ]]; then +if [[ -n "${USE_INSTRUMENTED_LIBCPP}" || "${BUILD_LIBFUZZER_WITH_LIBCXX}" == "1" ]]; then ${CI_RETRY_EXE} git clone --depth=1 https://github.com/llvm/llvm-project -b "llvmorg-23.1.2" /llvm-project @@ -74,4 +74,8 @@ if [[ -n "${USE_INSTRUMENTED_LIBCPP}" ]]; then # https://github.com/llvm/llvm-project/issues/84348 + LLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" + if [[ "${BUILD_LIBFUZZER_WITH_LIBCXX}" == "1" ]]; then + LLVM_ENABLE_RUNTIMES="${LLVM_ENABLE_RUNTIMES};compiler-rt" + fi cmake -G Ninja -B /cxx_build/ \ - -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \ + -DLLVM_ENABLE_RUNTIMES="${LLVM_ENABLE_RUNTIMES}" \ -DCMAKE_BUILD_TYPE=Release \ @@ -80,2 +84,4 @@ if [[ -n "${USE_INSTRUMENTED_LIBCPP}" ]]; then -DCMAKE_CXX_COMPILER=clang++ \ + -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \ + -DCOMPILER_RT_USE_LIBCXX=ON \ -DLLVM_TARGETS_TO_BUILD=Native \ @@ -88,3 +94,12 @@ if [[ -n "${USE_INSTRUMENTED_LIBCPP}" ]]; then - ninja -C /cxx_build/ "$MAKEJOBS" + if [[ "${BUILD_LIBFUZZER_WITH_LIBCXX}" == "1" ]]; then + # Build the sanitizer-instrumented libc++ and libFuzzer with its private libc++. + ninja -C /cxx_build/ "$MAKEJOBS" cxx cxxabi clang_rt.fuzzer-x86_64 + # Replace Clang's system libFuzzer archive with the one built above. + FUZZER_RUNTIME_PATH="$(find /cxx_build -type f -name 'libclang_rt.fuzzer-x86_64.a' -print -quit)" + FUZZER_RUNTIME_INSTALL_PATH="$(clang -print-file-name=libclang_rt.fuzzer-x86_64.a)" + cp "${FUZZER_RUNTIME_PATH}" "${FUZZER_RUNTIME_INSTALL_PATH}" + else + ninja -C /cxx_build/ "$MAKEJOBS" + fi

  19. fanquake referenced this in commit f718a7049c on Dec 3, 2026
  20. fanquake commented at 11:19 AM on December 3, 2026: member

    I am not sure how tedious this is and whether this is worth it.

    Opened #37091 for any opinions.

  21. fanquake merged this on Dec 3, 2026
  22. fanquake closed this on Dec 3, 2026

  23. fanquake deleted the branch on Dec 3, 2026
  24. fanquake referenced this in commit c3646d6afd on Dec 3, 2026
  25. fanquake commented at 4:18 PM on December 3, 2026: member

    Backported to 32.x in #37052.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-12-04 12:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me