From 3ffa64cd4566cb2d14f6b871e02460f54e1d4da1 Mon Sep 17 00:00:00 2001 From: Frederik Wedel-Heinen Date: Sat, 4 Jan 2025 19:27:37 +0100 Subject: Pass functions with correct signatures to the evp_generic_fetch_xxx methods UBSan complains about functions being called with incorrect signatures. Relates to #22896 Reviewed-by: Paul Dale Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/26318) --- crypto/encode_decode/decoder_meth.c | 14 ++++++++++++-- crypto/encode_decode/encoder_meth.c | 14 ++++++++++++-- crypto/evp/asymcipher.c | 22 ++++++++++++++++------ crypto/evp/exchange.c | 22 ++++++++++++++++------ crypto/evp/kem.c | 22 ++++++++++++++++------ crypto/evp/keymgmt_meth.c | 22 ++++++++++++++++------ crypto/evp/signature.c | 22 ++++++++++++++++------ 7 files changed, 104 insertions(+), 34 deletions(-) diff --git a/crypto/encode_decode/decoder_meth.c b/crypto/encode_decode/decoder_meth.c index 2e70e8aa37..a9a8c81aa8 100644 --- a/crypto/encode_decode/decoder_meth.c +++ b/crypto/encode_decode/decoder_meth.c @@ -24,6 +24,16 @@ */ #define NAME_SEPARATOR ':' +static void ossl_decoder_free(void *data) +{ + OSSL_DECODER_free(data); +} + +static int ossl_decoder_up_ref(void *data) +{ + return OSSL_DECODER_up_ref(data); +} + /* Simple method structure constructor and destructor */ static OSSL_DECODER *ossl_decoder_new(void) { @@ -191,8 +201,8 @@ static int put_decoder_in_store(void *store, void *method, return 0; return ossl_method_store_add(store, prov, id, propdef, method, - (int (*)(void *))OSSL_DECODER_up_ref, - (void (*)(void *))OSSL_DECODER_free); + ossl_decoder_up_ref, + ossl_decoder_free); } /* Create and populate a decoder method */ diff --git a/crypto/encode_decode/encoder_meth.c b/crypto/encode_decode/encoder_meth.c index adf34bbb9f..4a6a4036f0 100644 --- a/crypto/encode_decode/encoder_meth.c +++ b/crypto/encode_decode/encoder_meth.c @@ -24,6 +24,16 @@ */ #define NAME_SEPARATOR ':' +static void ossl_encoder_free(void *data) +{ + OSSL_ENCODER_free(data); +} + +static int ossl_encoder_up_ref(void *data) +{ + return OSSL_ENCODER_up_ref(data); +} + /* Simple method structure constructor and destructor */ static OSSL_ENCODER *ossl_encoder_new(void) { @@ -191,8 +201,8 @@ static int put_encoder_in_store(void *store, void *method, return 0; return ossl_method_store_add(store, prov, id, propdef, method, - (int (*)(void *))OSSL_ENCODER_up_ref, - (void (*)(void *))OSSL_ENCODER_free); + ossl_encoder_up_ref, + ossl_encoder_free); } /* Create and populate a encoder method */ diff --git a/crypto/evp/asymcipher.c b/crypto/evp/asymcipher.c index d22ab2a01a..945c917c96 100644 --- a/crypto/evp/asymcipher.c +++ b/crypto/evp/asymcipher.c @@ -17,6 +17,16 @@ #include "crypto/evp.h" #include "evp_local.h" +static void evp_asym_cipher_free(void *data) +{ + EVP_ASYM_CIPHER_free(data); +} + +static int evp_asym_cipher_up_ref(void *data) +{ + return EVP_ASYM_CIPHER_up_ref(data); +} + static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation, const OSSL_PARAM params[]) { @@ -484,8 +494,8 @@ EVP_ASYM_CIPHER *EVP_ASYM_CIPHER_fetch(OSSL_LIB_CTX *ctx, const char *algorithm, { return evp_generic_fetch(ctx, OSSL_OP_ASYM_CIPHER, algorithm, properties, evp_asym_cipher_from_algorithm, - (int (*)(void *))EVP_ASYM_CIPHER_up_ref, - (void (*)(void *))EVP_ASYM_CIPHER_free); + evp_asym_cipher_up_ref, + evp_asym_cipher_free); } EVP_ASYM_CIPHER *evp_asym_cipher_fetch_from_prov(OSSL_PROVIDER *prov, @@ -495,8 +505,8 @@ EVP_ASYM_CIPHER *evp_asym_cipher_fetch_from_prov(OSSL_PROVIDER *prov, return evp_generic_fetch_from_prov(prov, OSSL_OP_ASYM_CIPHER, algorithm, properties, evp_asym_cipher_from_algorithm, - (int (*)(void *))EVP_ASYM_CIPHER_up_ref, - (void (*)(void *))EVP_ASYM_CIPHER_free); + evp_asym_cipher_up_ref, + evp_asym_cipher_free); } int EVP_ASYM_CIPHER_is_a(const EVP_ASYM_CIPHER *cipher, const char *name) @@ -527,8 +537,8 @@ void EVP_ASYM_CIPHER_do_all_provided(OSSL_LIB_CTX *libctx, evp_generic_do_all(libctx, OSSL_OP_ASYM_CIPHER, (void (*)(void *, void *))fn, arg, evp_asym_cipher_from_algorithm, - (int (*)(void *))EVP_ASYM_CIPHER_up_ref, - (void (*)(void *))EVP_ASYM_CIPHER_free); + evp_asym_cipher_up_ref, + evp_asym_cipher_free); } diff --git a/crypto/evp/exchange.c b/crypto/evp/exchange.c index d9eed1cea5..693caa56c9 100644 --- a/crypto/evp/exchange.c +++ b/crypto/evp/exchange.c @@ -18,6 +18,16 @@ #include "crypto/evp.h" #include "evp_local.h" +static void evp_keyexch_free(void *data) +{ + EVP_KEYEXCH_free(data); +} + +static int evp_keyexch_up_ref(void *data) +{ + return EVP_KEYEXCH_up_ref(data); +} + static EVP_KEYEXCH *evp_keyexch_new(OSSL_PROVIDER *prov) { EVP_KEYEXCH *exchange = OPENSSL_zalloc(sizeof(EVP_KEYEXCH)); @@ -172,8 +182,8 @@ EVP_KEYEXCH *EVP_KEYEXCH_fetch(OSSL_LIB_CTX *ctx, const char *algorithm, { return evp_generic_fetch(ctx, OSSL_OP_KEYEXCH, algorithm, properties, evp_keyexch_from_algorithm, - (int (*)(void *))EVP_KEYEXCH_up_ref, - (void (*)(void *))EVP_KEYEXCH_free); + evp_keyexch_up_ref, + evp_keyexch_free); } EVP_KEYEXCH *evp_keyexch_fetch_from_prov(OSSL_PROVIDER *prov, @@ -183,8 +193,8 @@ EVP_KEYEXCH *evp_keyexch_fetch_from_prov(OSSL_PROVIDER *prov, return evp_generic_fetch_from_prov(prov, OSSL_OP_KEYEXCH, algorithm, properties, evp_keyexch_from_algorithm, - (int (*)(void *))EVP_KEYEXCH_up_ref, - (void (*)(void *))EVP_KEYEXCH_free); + evp_keyexch_up_ref, + evp_keyexch_free); } int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx) @@ -562,8 +572,8 @@ void EVP_KEYEXCH_do_all_provided(OSSL_LIB_CTX *libctx, evp_generic_do_all(libctx, OSSL_OP_KEYEXCH, (void (*)(void *, void *))fn, arg, evp_keyexch_from_algorithm, - (int (*)(void *))EVP_KEYEXCH_up_ref, - (void (*)(void *))EVP_KEYEXCH_free); + evp_keyexch_up_ref, + evp_keyexch_free); } int EVP_KEYEXCH_names_do_all(const EVP_KEYEXCH *keyexch, diff --git a/crypto/evp/kem.c b/crypto/evp/kem.c index f96012ccf0..6cb7ea8a8e 100644 --- a/crypto/evp/kem.c +++ b/crypto/evp/kem.c @@ -17,6 +17,16 @@ #include "crypto/evp.h" #include "evp_local.h" +static void evp_kem_free(void *data) +{ + EVP_KEM_free(data); +} + +static int evp_kem_up_ref(void *data) +{ + return EVP_KEM_up_ref(data); +} + static int evp_kem_init(EVP_PKEY_CTX *ctx, int operation, const OSSL_PARAM params[], EVP_PKEY *authkey) { @@ -452,8 +462,8 @@ EVP_KEM *EVP_KEM_fetch(OSSL_LIB_CTX *ctx, const char *algorithm, { return evp_generic_fetch(ctx, OSSL_OP_KEM, algorithm, properties, evp_kem_from_algorithm, - (int (*)(void *))EVP_KEM_up_ref, - (void (*)(void *))EVP_KEM_free); + evp_kem_up_ref, + evp_kem_free); } EVP_KEM *evp_kem_fetch_from_prov(OSSL_PROVIDER *prov, const char *algorithm, @@ -461,8 +471,8 @@ EVP_KEM *evp_kem_fetch_from_prov(OSSL_PROVIDER *prov, const char *algorithm, { return evp_generic_fetch_from_prov(prov, OSSL_OP_KEM, algorithm, properties, evp_kem_from_algorithm, - (int (*)(void *))EVP_KEM_up_ref, - (void (*)(void *))EVP_KEM_free); + evp_kem_up_ref, + evp_kem_free); } int EVP_KEM_is_a(const EVP_KEM *kem, const char *name) @@ -491,8 +501,8 @@ void EVP_KEM_do_all_provided(OSSL_LIB_CTX *libctx, { evp_generic_do_all(libctx, OSSL_OP_KEM, (void (*)(void *, void *))fn, arg, evp_kem_from_algorithm, - (int (*)(void *))EVP_KEM_up_ref, - (void (*)(void *))EVP_KEM_free); + evp_kem_up_ref, + evp_kem_free); } int EVP_KEM_names_do_all(const EVP_KEM *kem, diff --git a/crypto/evp/keymgmt_meth.c b/crypto/evp/keymgmt_meth.c index c9c09f7dac..8ad9292ce9 100644 --- a/crypto/evp/keymgmt_meth.c +++ b/crypto/evp/keymgmt_meth.c @@ -17,6 +17,16 @@ #include "crypto/evp.h" #include "evp_local.h" +static void evp_keymgmt_free(void *data) +{ + EVP_KEYMGMT_free(data); +} + +static int evp_keymgmt_up_ref(void *data) +{ + return EVP_KEYMGMT_up_ref(data); +} + static void *keymgmt_new(void) { EVP_KEYMGMT *keymgmt = NULL; @@ -268,8 +278,8 @@ EVP_KEYMGMT *evp_keymgmt_fetch_from_prov(OSSL_PROVIDER *prov, return evp_generic_fetch_from_prov(prov, OSSL_OP_KEYMGMT, name, properties, keymgmt_from_algorithm, - (int (*)(void *))EVP_KEYMGMT_up_ref, - (void (*)(void *))EVP_KEYMGMT_free); + evp_keymgmt_up_ref, + evp_keymgmt_free); } EVP_KEYMGMT *EVP_KEYMGMT_fetch(OSSL_LIB_CTX *ctx, const char *algorithm, @@ -277,8 +287,8 @@ EVP_KEYMGMT *EVP_KEYMGMT_fetch(OSSL_LIB_CTX *ctx, const char *algorithm, { return evp_generic_fetch(ctx, OSSL_OP_KEYMGMT, algorithm, properties, keymgmt_from_algorithm, - (int (*)(void *))EVP_KEYMGMT_up_ref, - (void (*)(void *))EVP_KEYMGMT_free); + evp_keymgmt_up_ref, + evp_keymgmt_free); } int EVP_KEYMGMT_up_ref(EVP_KEYMGMT *keymgmt) @@ -343,8 +353,8 @@ void EVP_KEYMGMT_do_all_provided(OSSL_LIB_CTX *libctx, evp_generic_do_all(libctx, OSSL_OP_KEYMGMT, (void (*)(void *, void *))fn, arg, keymgmt_from_algorithm, - (int (*)(void *))EVP_KEYMGMT_up_ref, - (void (*)(void *))EVP_KEYMGMT_free); + evp_keymgmt_up_ref, + evp_keymgmt_free); } int EVP_KEYMGMT_names_do_all(const EVP_KEYMGMT *keymgmt, diff --git a/crypto/evp/signature.c b/crypto/evp/signature.c index 7d619edfae..08082108ea 100644 --- a/crypto/evp/signature.c +++ b/crypto/evp/signature.c @@ -20,6 +20,16 @@ #include "crypto/evp.h" #include "evp_local.h" +static void evp_signature_free(void *data) +{ + EVP_SIGNATURE_free(data); +} + +static int evp_signature_up_ref(void *data) +{ + return EVP_SIGNATURE_up_ref(data); +} + static EVP_SIGNATURE *evp_signature_new(OSSL_PROVIDER *prov) { EVP_SIGNATURE *signature = OPENSSL_zalloc(sizeof(EVP_SIGNATURE)); @@ -404,8 +414,8 @@ EVP_SIGNATURE *EVP_SIGNATURE_fetch(OSSL_LIB_CTX *ctx, const char *algorithm, { return evp_generic_fetch(ctx, OSSL_OP_SIGNATURE, algorithm, properties, evp_signature_from_algorithm, - (int (*)(void *))EVP_SIGNATURE_up_ref, - (void (*)(void *))EVP_SIGNATURE_free); + evp_signature_up_ref, + evp_signature_free); } EVP_SIGNATURE *evp_signature_fetch_from_prov(OSSL_PROVIDER *prov, @@ -415,8 +425,8 @@ EVP_SIGNATURE *evp_signature_fetch_from_prov(OSSL_PROVIDER *prov, return evp_generic_fetch_from_prov(prov, OSSL_OP_SIGNATURE, algorithm, properties, evp_signature_from_algorithm, - (int (*)(void *))EVP_SIGNATURE_up_ref, - (void (*)(void *))EVP_SIGNATURE_free); + evp_signature_up_ref, + evp_signature_free); } int EVP_SIGNATURE_is_a(const EVP_SIGNATURE *signature, const char *name) @@ -448,8 +458,8 @@ void EVP_SIGNATURE_do_all_provided(OSSL_LIB_CTX *libctx, evp_generic_do_all(libctx, OSSL_OP_SIGNATURE, (void (*)(void *, void *))fn, arg, evp_signature_from_algorithm, - (int (*)(void *))EVP_SIGNATURE_up_ref, - (void (*)(void *))EVP_SIGNATURE_free); + evp_signature_up_ref, + evp_signature_free); } -- cgit v1.2.3