8000 ci: the ASAN job reports a false positive against Nix's unannotated boost fiber · Issue #89 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

ci: the ASAN job reports a false positive against Nix's unannotated boost fiber #89

Closed

Description

@Lillecarl

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_fcontext created.

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:

  • ucontext costs a sigprocmask system call for each switch. The suite dumps
    many paths, so measure the run time against the current one.
  • libboost_context.so becomes unused on this path, because swapcontext
    replaces make_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

Refs #64, #76.

Activity

  1. Lillecarl commented on Aug 4, 2026

    @Lillecarl
    ContributorAuthor

    Fixed, and measured

    nix/sanitizer.nix gives the ASAN variant -DBOOST_USE_UCONTEXT -DBOOST_USE_ASAN,
    and gives it a boost built with context-impl=ucontext, define=BOOST_USE_ASAN
    and linkflags=-fsanitize=address.

    The defines alone do not work. fiber_activation_record::current() is
    BOOST_CONTEXT_DECL, so it lives in the compiled library, and nixpkgs builds
    boost.context with the fcontext backend. Its libboost_context.so exports
    eight symbols: five of stack_traits, and jump_fcontext, make_fcontext
    and ontop_fcontext. The build failed with ten undefined references to
    current(), and nothing else. boost needs define=BOOST_USE_ASAN too, because
    that define adds three members to fiber_activation_record and the library
    constructs the struct.

    Run 30860160011 against run 30883251498, same job and same version:

    before after
    fatal ASAN reports 2 0
    tests completed 686 686
    suite wall time 45.7 min 42.5 min
    failing tests 19 20
    build time 26 min 25 min

    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.asanBuild keeps the UBSan cap.

    The job still finds a real defect

    Run 30889865286 restores both halves of #63 over this fix:

    ==5620==ERROR: AddressSanitizer: stack-use-after-return
    SUMMARY: AddressSanitizer: stack-use-after-return ../git.cc:408 in
      nix::fetchers::GitInputScheme::RepoInfo::warnDirty(nix::fetchers::Settings const&)
    
    Address is located in stack of thread T122 at offset 1408 in frame
      [928, 2112) 'stack_settings' (line 118) <== Memory access at offset 1408 is inside this variable
    

    stack-buffer-overflow count in that run: 0. stack-use-after-return
    count: 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_return
    warning". 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/swapcontext and
    links 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.

  2. added
    source: nanopynix
    on Oct 19, 2026
  3. added theissue type on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    source: nanopynix

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0