<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [coroutines] Destroying a coroutine inside await_suspend with symmetric-transfer form hits asan use-after-free in non-optimized builds"
   href="https://bugs.llvm.org/show_bug.cgi?id=47475">47475</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[coroutines] Destroying a coroutine inside await_suspend with symmetric-transfer form hits asan use-after-free in non-optimized builds
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>lewissbaker@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>See <a href="https://godbolt.org/z/G7xM8G">https://godbolt.org/z/G7xM8G</a>

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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>