fuzz: unpoison argc/argv in LLVMFuzzerInitialize under MSan

bitcoin/bitcoin: PR #37047

Review completed with no actionable findings.

Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

The downstream workaround addressed initialized argument values carrying stale MSan shadow across an uninstrumented-to-instrumented boundary. Its root-cause account says use-after-destruction instrumentation poisoned temporary-object stack storage during static initialization. On Ubuntu 24.04/glibc 2.39, uninstrumented libFuzzer main reused overlapping storage for its argc/argv locals without clearing that shadow, then passed their addresses to instrumented LLVMFuzzerInitialize. Reading argc consequently produced a false positive with the origin “Member fields were destroyed.”

At the pinned base, LLVMFuzzerInitialize immediately reads both pointed-to values in SetArgs(*argc, *argv). The head places unpoisoning before those reads. The historical distinction is between valid argument data and invalid shadow metadata—not permission to ignore genuinely uninitialized application data.

Source 1

The downstream proposal deliberately covered the complete argument representation: the argc and argv slots, the argument-pointer array including its trailing null entry, and each argument string. It explicitly stated that this boundary treatment kept full MSan and use-after-destruction checking intact, and reported successful libFuzzer/MSan initialization and seed-corpus execution.

The head imports that same scope under the MSan feature guard. Its historical purpose was to restore reliable fuzzing diagnostics without disabling the checks that exposed the stale shadow. Earlier Bitcoin Core discussion had instead accepted dropping libFuzzer from the MSan CI task because of repeated false positives, at the cost of the short fuzz-from-scratch sanity run for targets without a corpus.

Source 1 · Source 2 · Source 3

Ralph's inferences

The boundary assumption is that libFuzzer supplies a valid, initialized process-argument structure, although its uninstrumented caller does not reliably establish matching MSan shadow. Unpoisoning a pointer slot is not recursive: clearing the argv local's shadow only makes the char** value readable; it does not clear shadow for argv[i] pointer entries or the bytes those pointers reference. Clearing the array separately makes those pointers readable, and clearing each string makes character inspection and strlen safe from stale-shadow reports. Including argc + 1 entries also covers the terminating null pointer.

SetArgs traverses all three levels: it consumes argc, loads argv[i], and reads string contents through strlen and character comparisons. Thus clearing only the two caller stack slots addresses the first reported failure but does not establish initialized shadow for the entire argument structure consumed by the harness. This explains the broader boundary scope without claiming that every layer was independently observed failing.

Source 1