https://bugs.llvm.org/show_bug.cgi?id=47475

            Bug ID: 47475
           Summary: [coroutines] Destroying a coroutine inside
                    await_suspend with symmetric-transfer form hits asan
                    use-after-free in non-optimized builds
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangb...@nondot.org
          Reporter: lewissba...@gmail.com
                CC: llvm-bugs@lists.llvm.org, neeil...@live.com,
                    richard-l...@metafoo.co.uk

See https://godbolt.org/z/G7xM8G

The problem seems to be with the code generated for symmetric-transfer style
suspend-points (where await_suspend() returns a coroutine_handle to be
resumed).

Under non-optimised builds the compiler generates code that materializes the
returned coroutine_handle as a temporary in before then calling
__builtin_coro_resume() on its address. However, it materializes the
coroutine_handle using storage from the coroutine-frame rather than
materializing it on the stack.

For coroutines that destroy themselves inside await_suspend(), this results in
a use-after-free, as the compiler is trying to write the materialized
coroutine_handle to the now-freed coroutine frame upon return of
await_suspend().

It should instead be materializing the returned coroutine_handle on the stack.

This is unlikely to be an issue under optimised builds as the returned
coroutine_handle is generally kept in a register.

This seems to have been an issue since Clang 7, when symmetric-transfer was
first introduced.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to