Repository navigation
curl: Fix UAF on clone due to callback data pointer mismatch #24760
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
Closed
+35
−2
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -813,6 +813,10 @@ static int curl_ssh_hostkeyfunction(void *clientp, int keytype, const char *key, | |
| php_curl *ch = (php_curl *)clientp; | ||
| int rval = CURLKHMATCH_MISMATCH; /* cancel connection in case of an exception */ | ||
|
|
||
| if (!ZEND_FCC_INITIALIZED(ch->handlers.sshhostkey)) { | ||
| return rval; | ||
| } | ||
|
|
||
| #if PHP_CURL_DEBUG | ||
| fprintf(stderr, "curl_ssh_hostkeyfunction() called\n"); | ||
| fprintf(stderr, "clientp = %x, keytype = %d, key = %s, keylen = %zu\n", clientp, keytype, key, keylen); | ||
|
|
@@ -1284,8 +1288,11 @@ static void php_curl_copy_fcc_with_option(php_curl *ch, CURLoption option, zend_ | |
| { | ||
| if (ZEND_FCC_INITIALIZED(*source_fcc)) { | ||
| zend_fcc_dup(target_fcc, source_fcc); | ||
| curl_easy_setopt(ch->cp, option, (void *) ch); | ||
| } | ||
|
|
||
| /* The callback data (i.e. pointer to the curl handle) stays even if a user callback | ||
| * is reset to NULL. Ensure the data pointer always points to the new handle. */ | ||
| curl_easy_setopt(ch->cp, option, (void *) ch); | ||
| } | ||
|
|
||
| void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source) | ||
|
|
@@ -1325,7 +1332,6 @@ void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source) | |
| curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch); | ||
| curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch); | ||
| curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch); | ||
| curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, (void *) ch); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already done now by the php_curl_copy_fcc_with_option CURLOPT_DEBUGDATA code below |
||
|
|
||
| php_curl_copy_fcc_with_option(ch, CURLOPT_PROGRESSDATA, &ch->handlers.progress, &source->handlers.progress); | ||
| php_curl_copy_fcc_with_option(ch, CURLOPT_XFERINFODATA, &ch->handlers.xferinfo, &source->handlers.xferinfo); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| --TEST-- | ||
| Cloning a curl handle whose CURLOPT_PROGRESSFUNCTION was reset to null must not reference the source handle | ||
| --EXTENSIONS-- | ||
| curl | ||
| --FILE-- | ||
| <?php | ||
| $srcfile = __DIR__ . '/curl_copy_handle_progress_null_uaf.txt'; | ||
| file_put_contents($srcfile, "Test."); | ||
|
|
||
| $ch1 = curl_init(); | ||
| curl_setopt($ch1, CURLOPT_URL, "file://" . $srcfile); | ||
| curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true); | ||
| curl_setopt($ch1, CURLOPT_NOPROGRESS, false); | ||
| curl_setopt($ch1, CURLOPT_PROGRESSFUNCTION, fn() => 0); | ||
| curl_setopt($ch1, CURLOPT_PROGRESSFUNCTION, null); | ||
|
|
||
| $ch2 = clone $ch1; | ||
| unset($ch1); | ||
|
|
||
| var_dump(curl_exec($ch2)); | ||
| ?> | ||
| --CLEAN-- | ||
| <?php | ||
| @unlink(__DIR__ . '/curl_copy_handle_progress_null_uaf.txt'); | ||
| ?> | ||
| --EXPECT-- | ||
| string(5) "Test." |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is adjacently related, matches other handlers, otherwise a nulled callback can crash