fuzz: unpoison argc/argv in LLVMFuzzerInitialize under MSan

bitcoin/bitcoin: PR #37047

The review is inconclusive; no findings were published.

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 earlier removal was a pragmatic response to recurring false positives of explicitly unknown cause, not a documented diagnosis confined to stale argc/argv shadow state. Its author considered libFuzzer largely unmaintained and unnecessary for the CI task, accepting the loss of extra statistics and the 60-second empty-corpus sanity check.

Restoring fuzzer,memory reverses a reliability-versus-test-coverage tradeoff. The historical record does not establish that the new argument-boundary workaround addresses the sole cause behind the earlier removal. A participant also reported successfully combining libFuzzer and MSan in a different LLVM/setup configuration, suggesting that the incompatibility was not considered universal.

Source 1 · Source 2

The later OSS-Fuzz workaround provides a specific causal diagnosis for the observed Ubuntu 24.04 failure: MSan use-after-destruction instrumentation poisons stack bytes during static C++ initialization; uninstrumented libFuzzer main then places argc/argv locals over those bytes without clearing their shadow and passes their addresses to instrumented LLVMFuzzerInitialize. Reading *argc in SetArgs produces a false positive with origin 'Member fields were destroyed'.

This explains why actual initialized argument values can nevertheless trigger MSan before target initialization. The pinned base immediately calls SetArgs(*argc, *argv); the head inserts unpoisoning immediately before that call. The downstream description connects this mechanism to the earlier failures, but that retrospective attribution is not proof that all recurring warnings shared it.

Source 1

The downstream approach deliberately unpoisons the argument objects, pointer array including its trailing null entry, and argument strings, while retaining MSan and use-after-destruction checking elsewhere. Its description reports successful local libfuzzer/memory builds and full seed-corpus execution on Ubuntu 24.04 with no MSan errors.

The stated tradeoff is a narrow correction at an uninstrumented-to-instrumented boundary rather than globally disabling a sanitizer check. The reported verification supports that particular downstream environment; it does not establish a general initialization guarantee across LLVM and runtime configurations.

Source 1

Ralph's inferences

The region sizes follow the ordinary process-argument layout: sizeof(*argc) covers the integer object; sizeof(*argv) covers the argv-pointer object; (argc + 1) pointer entries cover the vector and its null sentinel; and each string operation covers an argument through its terminator. This accounts for each level of indirection rather than treating unpoisoning one pointer as initializing its pointees.

The ordering first makes the count and vector pointer readable, then the pointer entries, then the strings. This matches the base SetArgs implementation, which reads the count, indexes argv, and calls strlen. Its justification depends on these being valid, already initialized process arguments supplied by the engine—not arbitrary uninitialized target data. The inspected record supplies that premise as the downstream diagnosis, not an independently verified formal libFuzzer/MSan guarantee.

Source 1