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

Manually merged
fanquake merged 1 commit from fuzz_msan_unpoison_argv into master 2026-12-03 12:34:18 +00:00 AGit
fanquake commented 2026-12-02 14:35:34 +00:00 (Migrated from github.com)

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?

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`?
fanquake commented 2026-12-02 14:35:43 +00:00 (Migrated from github.com)

cc @maflcko

cc @maflcko
DrahtBot commented 2026-12-02 14:35:47 +00:00 (Migrated from github.com)

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

External sites

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 <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #35911 (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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/37047 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/37047.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/37047#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [maflcko](https://github.com/bitcoin/bitcoin/pull/37047#issuecomment-7375183095) | 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](https://github.com/bitcoin/bitcoin/pull/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-->
First-time contributor

I found no actionable issues in this static review.


Reviewed: e4426584148c · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:e1a29e5e677c47d383756f0fcf8f3760725c91d1104dd3ccb2f333b6217eba26:47880f5569fd2047d249266f337c4f2a509adf7d96c3ccb1c7644c2c2a650bff --> <!-- ralph-base:6fb33164bc3c42f4fe30ce70146763a524312af7 --> <!-- ralph-head:e4426584148c3bd9dc0c0db2f1130eeafa788e50 --> <!-- ralph-case:e03f3a16dc72e912c4c69daff550502a057a083197dacb696b63098680cc42bb --> I found no actionable issues in this static review. <!-- Review tier: routine --> --- Reviewed: [`e4426584148c`](<https://git.fish.foo/bitcoin/bitcoin/commit/e4426584148c3bd9dc0c0db2f1130eeafa788e50>) · [Review report](<https://review.fish.foo/report/37047-e4426584148c3bd9dc0c0db2f1130eeafa788e50-3472-3.html>) · [Previous reports](<https://review.fish.foo/traces/37047/>) [permalink](<https://review.fish.foo/report/37047-e4426584148c3bd9dc0c0db2f1130eeafa788e50-3472-3.html>)
DrahtBot commented 2026-12-02 15:41:29 +00:00 (Migrated from github.com)

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

Hints

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.

<!--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>
maflcko commented 2026-12-02 17:51:16 +00:00 (Migrated from github.com)

thx. Seems fine. Could revert https://github.com/bitcoin/bitcoin/pull/33666 to get back the 60s of empty fuzzing?

Though, ideally this is fixed upstream some time in the future in llvm in github.com/llvm/llvm-project@932dda8e34/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.

thx. Seems fine. Could revert https://github.com/bitcoin/bitcoin/pull/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.
fanquake commented 2026-12-03 10:20:51 +00:00 (Migrated from github.com)

Could revert https://github.com/bitcoin/bitcoin/pull/33666 to get back the 60s of empty fuzzing?

Thanks. Pulled in a reversion.

> Could revert https://github.com/bitcoin/bitcoin/pull/33666 to get back the 60s of empty fuzzing? Thanks. Pulled in a reversion.
maflcko commented 2026-12-03 10:23:29 +00:00 (Migrated from github.com)

thx. Though there is now a linker error.

review ACK 46a9b9ae9b 🔷

Show signature

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==
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>
fanquake commented 2026-12-03 10:24:01 +00:00 (Migrated from github.com)

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.

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.
maflcko commented 2026-12-03 10:24:17 +00:00 (Migrated from github.com)

ok:

review ACK e442658414 🤜

Show signature

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==
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>
fanquake commented 2026-12-03 10:25:22 +00:00 (Migrated from github.com)
Opened https://github.com/google/oss-fuzz/pull/16733 downstream.
maflcko commented 2026-12-03 10:26:29 +00:00 (Migrated from github.com)

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.

> 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
fanquake commented 2026-12-03 11:19:16 +00:00 (Migrated from github.com)

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

Opened #37091 for any opinions.

> I am not sure how tedious this is and whether this is worth it. Opened #37091 for any opinions.
fanquake commented 2026-12-03 16:18:05 +00:00 (Migrated from github.com)

Backported to 32.x in #37052.

Backported to `32.x` in #37052.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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
bitcoin/bitcoin!37047
No description provided.