Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use heap after free in libcurl linked with Schannel #10309

Closed
sergio-nsk opened this issue Jan 16, 2023 · 5 comments
Closed

Use heap after free in libcurl linked with Schannel #10309

sergio-nsk opened this issue Jan 16, 2023 · 5 comments
Assignees
Labels

Comments

@sergio-nsk
Copy link
Contributor

sergio-nsk commented Jan 16, 2023

From here, in multi_runsingle() on the line curl/lib/multi.c:1934, host.rawalloc is freed: Curl_safefree(existing->host.rawalloc);

1: 0x1870da80 is located 0 bytes inside of 26-byte region [0x1870da80,0x1870da9a)
1: freed by thread T0 here:
1:     #0 0x14ba221 in free D:\a01\_work\38\s\src\vctools\crt\asan\llvm\compiler-rt\lib\asan\asan_malloc_win.cpp:109
1:     #1 0x1b2323c in reuse_conn C:\actions-runner\_work\client\client\third-party\curl\lib\url.c:3387
1:     #2 0x1b1bde6 in create_conn C:\actions-runner\_work\client\client\third-party\curl\lib\url.c:3747
1:     #3 0x1b16b0c in Curl_connect C:\actions-runner\_work\client\client\third-party\curl\lib\url.c:3946
1:     #4 0x1b02c71 in multi_runsingle C:\actions-runner\_work\client\client\third-party\curl\lib\multi.c:1934

Later in the same function multi_runsingle() on the line curl/lib/multi.c:2469, it calls schannel_shutdown() on the line curl/lib/vtls/schannel.c:2505 that accesses connssl->hostname that definitely points to somewhere inside the freed memory.

1: ==476==ERROR: AddressSanitizer: heap-use-after-free on address 0x1870da80 at pc 0x014bf5f9 bp 0x004f779c sp 0x004f7790
1: READ of size 3 at 0x1870da80 thread T0
1:     #0 0x14bf611 in __asan_wrap_strlen D:\a01\_work\38\s\src\vctools\crt\asan\llvm\compiler-rt\lib\sanitizer_common\sanitizer_common_interceptors.inc:375
1:     #1 0x1b6b684 in dprintf_formatf C:\actions-runner\_work\client\client\third-party\curl\lib\mprintf.c:842
1:     #2 0x1b6[864](https://github.com/snxd/client/actions/runs/3934099623/jobs/6728495573#step:8:865)c in curl_mvsnprintf C:\actions-runner\_work\client\client\third-party\curl\lib\mprintf.c:1036
1:     #3 0x1b372c7 in Curl_infof C:\actions-runner\_work\client\client\third-party\curl\lib\sendf.c:251
1:     #4 0x1b84d36 in schannel_shutdown C:\actions-runner\_work\client\client\third-party\curl\lib\vtls\schannel.c:2505
1:     #5 0x1b8542f in schannel_close C:\actions-runner\_work\client\client\third-party\curl\lib\vtls\schannel.c:2596
1:     #6 0x1b2d654 in cf_close C:\actions-runner\_work\client\client\third-party\curl\lib\vtls\vtls.c:1439
1:     #7 0x1b2810f in ssl_cf_close C:\actions-runner\_work\client\client\third-party\curl\lib\vtls\vtls.c:1488
1:     #8 0x1b62c62 in Curl_conn_close C:\actions-runner\_work\client\client\third-party\curl\lib\cfilters.c:155
1:     #9 0x1b1ac21 in conn_shutdown C:\actions-runner\_work\client\client\third-party\curl\lib\url.c:749
1:     #10 0x1b16fa1 in Curl_disconnect C:\actions-runner\_work\client\client\third-party\curl\lib\url.c:861
1:     #11 0x1b01e9a in multi_done C:\actions-runner\_work\client\client\third-party\curl\lib\multi.c:721
1:     #12 0x1b03fe0 in multi_runsingle C:\actions-runner\_work\client\client\third-party\curl\lib\multi.c:2469

This seems to be similar to the issue #10273

cUrl version

libcurl v7.87.0

operating system

Windows 10, Windows 11

@sergio-nsk sergio-nsk changed the title Use heap after free libcurl linked with Schannel Use heap after free in libcurl linked with Schannel Jan 16, 2023
@dfandrich
Copy link
Contributor

dfandrich commented Jan 17, 2023 via email

@sergio-nsk
Copy link
Contributor Author

@dfandrich It's an issue of libcurl v7.87.0. It was a typo in the initial post, then I edited it.

@icing icing self-assigned this Jan 17, 2023
@icing
Copy link
Contributor

icing commented Jan 17, 2023

@sergio-nsk thanks for the details. I can now understand what happens here and it seems indeed the same cause as in #10273. Working on a fix.

icing added a commit to icing/curl that referenced this issue Jan 17, 2023
…ng the `connectdata` instance

since this may get free'ed on connection reuse. Refs curl#10309, curl#10273.
@icing
Copy link
Contributor

icing commented Jan 17, 2023

Please see #10310 as a fix for this and #10273.

@sergio-nsk
Copy link
Contributor Author

sergio-nsk commented Jan 17, 2023

@icing I have tried the fix. It seems to fix the issue. Great job, thank you.

Hope to get a corrective release 7.87.1 soon.

@jay jay closed this as completed in f8da4f2 Jan 20, 2023
@jay jay added TLS Windows Windows-specific labels Jan 20, 2023
bch pushed a commit to bch/curl that referenced this issue Jul 19, 2023
- Copy the hostname and dispname to ssl_connect_data.

Use a copy instead of referencing the `connectdata` instance since this
may get free'ed on connection reuse.

Reported-by: Stefan Talpalaru
Reported-by: sergio-nsk@users.noreply.github.com

Fixes curl#10273
Fixes curl#10309

Closes curl#10310
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants