]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Prevent potential UAF in init_thread_deregister()
authorjwalch <jeremy.walch@gmail.com>
Thu, 29 Oct 2020 17:32:49 +0000 (13:32 -0400)
committerTomas Mraz <tmraz@fedoraproject.org>
Mon, 2 Nov 2020 17:03:22 +0000 (18:03 +0100)
I discovered the potential for use-after-free on glob_tevent_reg &
its members in this function as a consequence of some static (de-)initialization
fiasco in C++ client code.

Long story short, an EVP_PKEY_free() was happening after
OPENSSL_cleanup(). Aside from being freed the EVP_PKEY object wasn't
actually being used after cleanup, it was basically just an
ordering issue.

Obviously the application behavior here is somewhat suspect,
but IMO is basically benign. Crashing (most typical outcome
of a UAF) doesn't seem the optimal response.

At any rate, the issue can be avoided (at least with regard to this function)
by simply updating the pointer to NULL rather than leaving it pointing
to the freed memory, as is the typical practice.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/13267)

crypto/initthread.c

index f460252ff9f68749f12b3d336af6af52df8a5179..93160f577ccdcea6c9866677f25c4bbcfe5ead91 100644 (file)
@@ -389,6 +389,8 @@ static int init_thread_deregister(void *index, int all)
         return 0;
     if (!all)
         CRYPTO_THREAD_write_lock(gtr->lock);
+    else
+        glob_tevent_reg = NULL;
     for (i = 0; i < sk_THREAD_EVENT_HANDLER_PTR_num(gtr->skhands); i++) {
         THREAD_EVENT_HANDLER **hands
             = sk_THREAD_EVENT_HANDLER_PTR_value(gtr->skhands, i);