Repository navigation
Description
test-asan-nix_2_31 goes red on a report that ASan makes against itself. The
report comes from Nix's boost coroutine, and not from any code of this
repository. The job is therefore red whatever the bindings do, so it cannot
gate anything until this is fixed.
Run 30860160011, job 91840170989.
What the job reports
Two identical reports, in two different worker processes:
==21992==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fa82775fd50 ...
WRITE of size 24 at 0x7fa82775fd50 thread T3
#0 sigaltstack.part.0 (libasan.so+0x8a723)
nixidae/nixidae#30 __asan::PlatformUnpoisonStacks() (libasan.so+0x1282b3)
nixidae/nixidae#31 __asan_handle_no_return (libasan.so+0x12ee4b)
nixidae/nixidae#32 std::function<void (unsigned long)>::~function()
nixidae/nixidae#33 operator() ../archive.cc:47
...
nixidae/nixidae#46 nix::SourceAccessor::dumpPath(...)
nixidae/nixidae#48 nix::fetchers::PathInputScheme::getAccessor(...)
nixidae/nixidae#53 operator() ../serialise.cc:292
nixidae/nixidae#54 boost/coroutine2/detail/pull_control_block_cc.ipp:88
nixidae/nixidae#58 run boost/context/fiber_fcontext.hpp:206
nixidae/nixidae#59 fiber_entry<boost::context::detail::fiber_record<...>>
nixidae/nixidae#60 make_fcontext (libboost_context.so.1.89.0+0x118e)
Address 0x7fa82775fd50 is a wild pointer inside of access range of size 0x18.
SUMMARY: AddressSanitizer: stack-buffer-overflow ../archive.cc:47 in operator()
Three facts in that trace name the cause:
- The write comes from
libasan.so. Frames 0 to 2 are the ASan runtime, and
no frame of Nix or of this repository writes anything. - The address is a wild pointer, which means ASan holds no shadow record of it.
- Frames 29 to 31 run on a boost fiber stack, which
make_fcontextcreated.
ASan says the same thing itself, before each report:
==20441==WARNING: ASan is ignoring requested __asan_handle_no_return:
stack type: default top: 0x7ba812bd4f00; bottom 0x7fa828da3000;
size: 0xfffffbffe9e31f00 (-4398417502464)
False positive error reports may follow
A stack of negative size is the whole diagnosis. ASan reads the bounds of the
thread stack, the code runs on a fiber stack somewhere else, and the
subtraction gives a meaningless number. PlatformUnpoisonStacks then writes
across that range and reports its own write.
The warning appears many times in the run, and only two of them reach a fatal
report. So the trigger is timing, and the job is not reliably red either.
Why the fiber is unannotated
ASan supports a stack switch through __sanitizer_start_switch_fiber and
__sanitizer_finish_switch_fiber. Boost.Context calls both, under
BOOST_USE_ASAN. It calls them in one implementation only:
| header | sites of the ASan annotation |
|---|---|
boost/context/fiber_ucontext.hpp |
14 |
boost/context/fiber_fcontext.hpp |
0 |
boost/context/fiber.hpp selects the ucontext implementation when
BOOST_USE_UCONTEXT is defined, and the fcontext implementation otherwise.
Nix defines neither, so it gets fcontext, and no annotation reaches ASan.
The trace above confirms which one the build uses.
Measured against
/nix/store/hl9mnablabykyx4q5dw7a9cdp2m1pclh-boost-1.89.0-dev, which is the
boost that this build links.
The candidate fix
Compile the asan variant of Nix with -DBOOST_USE_UCONTEXT -DBOOST_USE_ASAN. nix/sanitizer.nix already adds flags to each library of
the closure, so the flags have a place to go.
Two things need a measurement before this closes:
ucontextcosts asigprocmasksystem call for each switch. The suite dumps
many paths, so measure the run time against the current one.libboost_context.sobecomes unused on this path, becauseswapcontext
replacesmake_fcontext. Confirm that the link still succeeds.
An ASAN_OPTIONS suppression is not an alternative. ASan applies
suppressions= to a few error classes, and stack-buffer-overflow is not one
of them.
Acceptance
test-asan-nix_2_31completes the suite with no report fromarchive.cc,
and noASan is ignoring requested __asan_handle_no_returnwarning.- The run time of the job stays inside the cap that
ci/workflows/lib.nix
sets. - The job stays able to find a real defect. Restore the defect of bindings: parse_flake_ref returns a FlakeRef that points at a destroyed fetchers::Settings #63 again,
and require the job to report it.
Activity
fix(ci): tell ASAN that Nix switches to a coroutine stack
test(ci): run the ASAN jobs on every commit
fix(ci): tell ASAN that Nix switches to a coroutine stack
test(ci): run the ASAN jobs on every commit
fix(ci): tell ASAN that Nix switches to a coroutine stack
test(ci): run the ASAN jobs on every commit
test(asan): restore the #34 defect again, over the boost fix
Lillecarl commentedon Aug 4, 2026
Fixed, and measured
nix/sanitizer.nixgives the ASAN variant-DBOOST_USE_UCONTEXT -DBOOST_USE_ASAN,and gives it a boost built with
context-impl=ucontext,define=BOOST_USE_ASANand
linkflags=-fsanitize=address.The defines alone do not work.
fiber_activation_record::current()isBOOST_CONTEXT_DECL, so it lives in the compiled library, and nixpkgs buildsboost.context with the
fcontextbackend. Itslibboost_context.soexportseight symbols: five of
stack_traits, andjump_fcontext,make_fcontextand
ontop_fcontext. The build failed with ten undefined references tocurrent(), and nothing else. boost needsdefine=BOOST_USE_ASANtoo, becausethat define adds three members to
fiber_activation_recordand the libraryconstructs the struct.
Run 30860160011 against run 30883251498, same job and same version:
The extra failure is one more LSP test that the second run reached before the
same 60 minute timeout. Both runs fail the same flake and LSP tests, and both
time out, so neither belongs to this change. boost costs one minute less than
nothing measurable, so
caps.asanBuildkeeps the UBSan cap.The job still finds a real defect
Run 30889865286 restores both halves of #63 over this fix:
stack-buffer-overflowcount in that run: 0.stack-use-after-returncount: 2. ASAN names the variable and the line, and reports nothing else.
One acceptance criterion was wrong, and this corrects it
This issue asked for "no
ASan is ignoring requested __asan_handle_no_returnwarning". 28 of them remain, in 15 processes, each paired between a forked
child and the parent. That criterion asks upstream for something it does not
give: ASAN prints
ASan doesn't fully support makecontext/swapcontextandlinks google/sanitizers#189, which is open.
The criterion that matters is that no warning becomes a fatal report, and
that is met. A warning with no report costs a log line. A report stops the
run and reads as a defect of this repository.
The third criterion, that the job stays inside its cap, is met for the build
and not for the suite. That timeout predates this work, it happens with and
without this fix, and it has its own issue now.
fix(ci): tell ASAN that Nix switches to a coroutine stack
test(ci): run the ASAN jobs on every commit
fix(ci): tell ASAN that Nix switches to a coroutine stack