Skip to content

Curl_connect() tries to close an in-use HTTP/2 connection after OOM #23629

Closed

Description

@cmeister2

I did this

If setup_range() returns CURLE_OUT_OF_MEMORY after a transfer attaches to a multiplexed HTTP/2 connection, Curl_connect() detaches that transfer and calls Curl_conn_close(..., TRUE) while another transfer still owns the connection.

Current master asserts in cpool_discard_conn(); at curl 62a6ee5f, the same reproducer produces an ASan heap-use-after-free.

After detaching, Curl_connect() should only close the connection when !CONN_INUSE(conn).

Reproducer: repro.c and server.py attached.

repro-simple.c

cf494563-h2-server.py

I expected the following

Not to hit debug assert

curl/libcurl version

curl DEV

operating system

WSL2

Activity

  1. cmeister2 commented on Oct 27, 2026

    @cmeister2
    ContributorAuthor

    Running the attachments against current ASan/debug curl gives:

    Server terminal:

    $ uv run --with h2 cf494563-h2-server.py
    listening on http://127.0.0.1:18080

    Client terminal:

    $ ./repro
    rejecting setup_range() copy
    repro: lib/conncache.c:207: cpool_discard_conn: Assertion `0' failed.
    Aborted

    The client exits with status 134 (SIGABRT). The first line confirms the intended setup_range() allocation was rejected; the assertion confirms curl then tried to discard a connection still owned by another transfer.

    Against curl 62a6ee5 (i.e. pre-debugassert), the assertion is absent and ASan instead reports:

    ERROR: AddressSanitizer: heap-use-after-free
    READ in mstate_perform_pollset
    ...
    freed by Curl_conn_free
      cpool_discard_conn
      Curl_conn_close
      Curl_connect
  2. bagder commented on Oct 27, 2026

    @bagder
    Member

    While a UAF, I don't think we need to treat this as a vulnerability.

    Reasons:

    1. the OOM that is required is almost impossible to get in a modern system
    2. this problem cannot reasonably be triggered by an attacker
  3. cmeister2 commented on Oct 27, 2026

    @cmeister2
    ContributorAuthor

    Also worth mentioning this was discovered by OSS-Fuzz: https://issues.oss-fuzz.com/issues/578324120

  4. bagder commented on Oct 27, 2026

    @bagder
    Member

    When I remove the assert from the code in master I "only" get a memory leak instead. I think maybe @icing has an idea on the best fix here?

  5. icing commented on Oct 28, 2026

    @icing
    Contributor

    I think I can propose a PR for fixing this happy little accident.

  6. added a commit that references this issue on Nov 18, 2026
    a9503c5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions