Fix a use-after-free in the child provider code
authorMatt Caswell <matt@openssl.org>
Fri, 14 May 2021 14:33:40 +0000 (15:33 +0100)
committerMatt Caswell <matt@openssl.org>
Mon, 17 May 2021 09:36:03 +0000 (10:36 +0100)
If the child provider context data gets cleaned up before all usage of
providers has finished then a use-after-free can occur. We change the
priority of this data so that it gets freed later.

Fixes #15284

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15286)

crypto/provider_child.c
include/internal/cryptlib.h

index 2487d43fd7a4215ce1c36b61b1eabe760c36c7be..14d005462419a1186f5229098d1c1161c0dedfe8 100644 (file)
@@ -47,7 +47,7 @@ static void child_prov_ossl_ctx_free(void *vgbl)
 }
 
 static const OSSL_LIB_CTX_METHOD child_prov_ossl_ctx_method = {
-    OSSL_LIB_CTX_METHOD_DEFAULT_PRIORITY,
+    OSSL_LIB_CTX_METHOD_LOW_PRIORITY,
     child_prov_ossl_ctx_new,
     child_prov_ossl_ctx_free,
 };
index d943419a52da7e9612753b32e2489c38b46bfe36..966c8f26f18c8c780468cbed84824be666eb5b4e 100644 (file)
@@ -168,6 +168,7 @@ typedef struct ossl_ex_data_global_st {
 # define OSSL_LIB_CTX_CHILD_PROVIDER_INDEX          18
 # define OSSL_LIB_CTX_MAX_INDEXES                   19
 
+# define OSSL_LIB_CTX_METHOD_LOW_PRIORITY          -1
 # define OSSL_LIB_CTX_METHOD_DEFAULT_PRIORITY       0
 # define OSSL_LIB_CTX_METHOD_PRIORITY_1             1
 # define OSSL_LIB_CTX_METHOD_PRIORITY_2             2