Skip to content

Commit

Permalink
Pass functions with correct signatures to the evp_generic_fetch_xxx f…
Browse files Browse the repository at this point in the history
…amily of methods. UBSan complains about functions being called with incorrect signatures. Relates to openssl#22896.
  • Loading branch information
fwh-dc committed Jan 4, 2025
1 parent f16b00e commit cb89cda
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 30 deletions.
22 changes: 16 additions & 6 deletions crypto/evp/asymcipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
#include "crypto/evp.h"
#include "evp_local.h"

static void evp_asym_cipher_free(void *data)
{
EVP_ASYM_CIPHER_free((EVP_ASYM_CIPHER *)data);
}

static int evp_asym_cipher_up_ref(void *data)
{
return EVP_ASYM_CIPHER_up_ref((EVP_ASYM_CIPHER *)data);
}

static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation,
const OSSL_PARAM params[])
{
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}


Expand Down
22 changes: 16 additions & 6 deletions crypto/evp/exchange.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
#include "crypto/evp.h"
#include "evp_local.h"

static void evp_keyexch_free(void *data)
{
EVP_KEYEXCH_free((EVP_KEYEXCH *)data);
}

static int evp_keyexch_up_ref(void *data)
{
return EVP_KEYEXCH_up_ref((EVP_KEYEXCH *)data);
}

static EVP_KEYEXCH *evp_keyexch_new(OSSL_PROVIDER *prov)
{
EVP_KEYEXCH *exchange = OPENSSL_zalloc(sizeof(EVP_KEYEXCH));
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 16 additions & 6 deletions crypto/evp/kem.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
#include "crypto/evp.h"
#include "evp_local.h"

static void evp_kem_free(void *data)
{
EVP_KEM_free((EVP_KEM *)data);
}

static int evp_kem_up_ref(void *data)
{
return EVP_KEM_up_ref((EVP_KEM *)data);
}

static int evp_kem_init(EVP_PKEY_CTX *ctx, int operation,
const OSSL_PARAM params[], EVP_PKEY *authkey)
{
Expand Down Expand Up @@ -452,17 +462,17 @@ 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,
const char *properties)
{
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)
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 16 additions & 6 deletions crypto/evp/keymgmt_meth.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,24 +261,34 @@ static void *keymgmt_from_algorithm(int name_id,
return keymgmt;
}

static void evp_keymgmt_free(void *data)
{
EVP_KEYMGMT_free((EVP_KEYMGMT *)data);
}

static int evp_keymgmt_up_ref(void *data)
{
return EVP_KEYMGMT_up_ref((EVP_KEYMGMT *)data);
}

EVP_KEYMGMT *evp_keymgmt_fetch_from_prov(OSSL_PROVIDER *prov,
const char *name,
const char *properties)
{
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,
const char *properties)
{
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)
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 16 additions & 6 deletions crypto/evp/signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
#include "crypto/evp.h"
#include "evp_local.h"

static void evp_signature_free(void *data)
{
EVP_SIGNATURE_free((EVP_SIGNATURE *)data);
}

static int evp_signature_up_ref(void *data)
{
return EVP_SIGNATURE_up_ref((EVP_SIGNATURE *)data);
}

static EVP_SIGNATURE *evp_signature_new(OSSL_PROVIDER *prov)
{
EVP_SIGNATURE *signature = OPENSSL_zalloc(sizeof(EVP_SIGNATURE));
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}


Expand Down

0 comments on commit cb89cda

Please sign in to comment.