mirror of
https://github.com/curl/curl.git
synced 2026-08-26 19:53:31 +03:00
hardening: add API guards
Add call stacks to easy and multi instances. Record ongoing API calls and callback invocations there to detect recursion and not allowed invocations. Define enums for easy, multi and callbacks in `api.h`. In `api.c` define properties for these functions: - can they recurse - is the easy/multi handle destroyed during the call or should it be good afterwards - is the call allowed when a multi event callback is ongoing - is the call allowed when a notification callback is ongoing Entering a guard - checks that passed CURL*/CURLM* are GOOD on entering - checks that easy handle's `mid` is correct and it is known for it in the multi. - checks that call properties are obeyed (recursion, callback checks) - checks that passed CURL*/CURLM* are GOOD on leaving, unless call is known to kill it Checks for ongoing callbacks inspect the whole call stack and catches nested invocations (which our current flags can not). Call stacks in easy/multi handle are fixed size and will deny recursion when the limit is reached. The current limits are 7 for easy and 15 for multi now. Removes: - multi->in_callback, check is done via call stack - multi->in_ntfy_cb, check is done via call stack The overhead in my tests seems minimal, if noticeable at all. Closes #22237
This commit is contained in:
parent
ab8d771d31
commit
dfc01ea2a3
30 changed files with 1667 additions and 943 deletions
|
|
@ -3961,6 +3961,7 @@ CURLcode Curl_ossl_ctx_init(struct ossl_ctx *octx,
|
|||
|
||||
/* give application a chance to interfere with SSL set up. */
|
||||
if(data->set.ssl.fsslctx) {
|
||||
struct Curl_mapi_guard guard;
|
||||
/* When a user callback is installed to modify the SSL_CTX,
|
||||
* we need to do the full initialization before calling it.
|
||||
* See: #11800 */
|
||||
|
|
@ -3970,10 +3971,10 @@ CURLcode Curl_ossl_ctx_init(struct ossl_ctx *octx,
|
|||
return result;
|
||||
octx->x509_store_setup = TRUE;
|
||||
}
|
||||
Curl_set_in_callback(data, TRUE);
|
||||
CURL_CBAPI_START(&guard, data, easy_fsslctx);
|
||||
result = (*data->set.ssl.fsslctx)(data, octx->ssl_ctx,
|
||||
data->set.ssl.fsslctxp);
|
||||
Curl_set_in_callback(data, FALSE);
|
||||
CURL_CBAPI_END(&guard);
|
||||
if(result) {
|
||||
failf(data, "error signaled by SSL ctx callback");
|
||||
return result;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue