summaryrefslogtreecommitdiffstats
path: root/crypto/provider_core.c
AgeCommit message (Collapse)Author
2023-12-04After initializing a provider, check if its output dispatch table is NULLRichard Levitte
If the provider's output dispatch table is NULL, trying to parse it causes a crash. Let's not do that. Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com> Reviewed-by: Todd Short <todd.short@me.com> (Merged from https://github.com/openssl/openssl/pull/22866) (cherry picked from commit 8fa65a6648554087a67102372e5e6c8b0fae0158)
2023-10-20rand: add callbacks to cleanup the user entropy resp. nonceMatthias St. Pierre
The `get_user_{entropy,nonce}` callbacks were add recently to the dispatch table in commit 4cde7585ce8e. Instead of adding corresponding `cleanup_user_{entropy,nonce}` callbacks, the `cleanup_{entropy,nonce}` callbacks were reused. This can cause a problem in the case where the seed source is replaced by a provider: the buffer gets allocated by the provider but cleared by the core. Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22423) (cherry picked from commit 5516d20226c496c2b22fa741698b4d48dad0428f)
2023-10-03fips: use seed source requestedPauli
Fixes #21909 Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22210)
2023-09-19Copyright year updatesRichard Levitte
Reviewed-by: Matt Caswell <matt@openssl.org> Release: yes
2023-08-04no_autoload: make the no-autoload-config option work again.Pauli
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/21621) (cherry picked from commit cb8e64131e7ce230a9268bdd7cc4664868ff0dc9)
2022-11-21Refactor OSSL_LIB_CTX to avoid using CRYPTO_EX_DATAHugo Landau
This refactors OSSL_LIB_CTX to avoid using CRYPTO_EX_DATA. The assorted objects to be managed by OSSL_LIB_CTX are hardcoded and are initialized eagerly rather than lazily, which avoids the need for locking on access in most cases. Fixes #17116. Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17881) (cherry picked from commit 927d0566ded0dff9d6c5abc8a40bb84068446b76)
2022-11-09prov: remove unused field `flag_fallback` and function ↵Pauli
`ossl_provider_set_fallback` These are legacy of older versions of the code and are currently not used anywhere. Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/16985) (cherry picked from commit 90c311315c15a4fea895fd317d9c8fe801ba04a0) Reviewed-by: Hugo Landau <hlandau@openssl.org>
2022-10-25Finer grained error records for provider load/init failuresRichard Levitte
When a provider is activated, these three cases would record that the provider init function failed (implying that it was called): - failure to load the provider module (in case it's a dynamically loadable module) - the init function not being present (i.e. being NULL) - the init function being called and returning an error indication (i.e. returning a false value) This is confusing. Separating the three cases so that they record different errors will make it easier to determine causes of failure. Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com> Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/19419) (cherry picked from commit 2d23ba14630551ee347acafcab81fa1a290c6504)
2022-10-25Fix a lock in provider_remove_store_methods()Matt Caswell
We were taking a read lock. It should have been a write lock. Fixes #19474 Reviewed-by: Tim Hudson <tjh@openssl.org> Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/19481) (cherry picked from commit 6962e21b7c51480343db1a275f52525754dcbe44)
2022-07-20Coverity 1503321 & 1503327: dereference after null checkPauli
The earlier fix being inadequate Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com> (Merged from https://github.com/openssl/openssl/pull/18822) (cherry picked from commit f913c3cd7e22eecbcc8f84b72c645081fa37fdf4)
2022-07-17Coverity 1503321 & 1503327: dereference after null checkPauli
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com> Reviewed-by: Hugo Landau <hlandau@openssl.org> (Merged from https://github.com/openssl/openssl/pull/18799) (cherry picked from commit f80910390cb882f346fe59c9803fc914b9c367c2)
2022-07-13Pre-declare all core dispatch table functions, and fix the internal onesRichard Levitte
When assigning pointers to functions in an OSSL_DISPATCH table, we try to ensure that those functions are properly defined or declared with an extra declaration using the corresponding function typedefs that are defined by include/openssl/core_dispatch.h. For the core dispatch table, found in crypto/provider_core.c, it seems we forgot this habit, and thus didn't ensure well enough that the function pointers that are assigned in the table can actually be used for those dispatch table indexes. This change adds all the missing declarations, and compensates for differences with functions that do the necessary casting, making those explicit rather than implicit, thereby trying to assure that we know what we're doing. One function is not fixed in this change, because there's a controversy, a clash between the signature of BIO_ctrl() and OSSL_FUNC_BIO_ctrl_fn. They have different return types. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/18198) (cherry picked from commit 9574842e90e29015daa2b071e965cec9aa885c17)
2022-06-28crypto/provider_core.c: Avoid calling unlock two timesPeiwei Hu
Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/18641) (cherry picked from commit 61f510600e2c7cdee6e61f8b7075fb0e939eb179)
2022-06-24Avoid including decoder/encoder/store headers into fips moduleTomas Mraz
Fixes #18618 Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/18630)
2022-06-21Update copyright yearMatt Caswell
Reviewed-by: Richard Levitte <levitte@openssl.org> Release: yes
2022-06-02Don't call ossl_provider_free() without first setting refcntMatt Caswell
The function ossl_provider_free() decrements the refcnt of the provider and frees it if it has reached 0. This only works if the refcnt has already been initialised. We must only call ossl_provider_free() after this initialisation - otherwise it will fail to free the provider correctly. Addresses the issue mentioned here: https://github.com/openssl/openssl/pull/18355#issuecomment-1138741857 Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/18417) (cherry picked from commit c4ed6f6f0ee700e0473def049659061dd52fd3fc)
2022-06-02Fix a memory leak is ossl_provider_doall_activatedMatt Caswell
If the callback fails then we don't correctly free providers that were already in our stack and that we up-refed earlier. Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/18413) (cherry picked from commit b4be10dfcd370960cecfda9773e1bfcc568a7390)
2022-05-05Add method store cache flush and method removal to non-EVP operationsRichard Levitte
evp_method_store_flush() and evp_method_store_remove_all_provided() only cover EVP operations, but not encoders, decoders and store loaders. This adds corresponding methods for those as well. Without this, their method stores are never cleaned up when the corresponding providers are deactivated or otherwise modified. Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/18151) (cherry picked from commit 32e3c071373280b69be02ba91fc3204495e2e1bf)
2022-05-05Make it possible to remove methods by the provider that provides themRichard Levitte
This adds ossl_method_store_remove_all_provided(), which selectively removes methods from the given store that are provided by the given provider. This also adds the EVP specific evp_method_store_remove_all_provided(), which matches ossl_method_store_remove_all_provided() but can also retrieve the correct store to manipulate for EVP functions. This allows us to modify ossl_provider_self_test() to do the job it's supposed to do, but through clearly defined functions instead of a cache flushing call that previously did more than that. ossl_provider_deactivate() is also modified to remove methods associated with the deactivated provider, and not just clearing the cache. Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/18151) (cherry picked from commit 2e4d0677ea858c619a33235265dbee19520a9d35)
2022-05-05Don't empty the method store when flushing the query cacheRichard Levitte
When evp_method_store_flush() flushed the query cache, it also freed all methods in the EVP method store, through an unfortunate call of ossl_method_store_flush_cache() with an argument saying that all methods should indeed be dropped. To undo some of the confusion, ossl_method_store_flush_cache() is renamed to ossl_method_store_cache_flush_all(), and limited to do only that. Some if the items in the internal ALGORITHM structure are also renamed and commented to clarify what they are for. Fixes #18150 Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/18151) (cherry picked from commit 60640d79ca7ea0980dc09c71fe6a297b5f8588a2)
2022-05-05Drop ossl_provider_clear_all_operation_bits() and all uses of itRichard Levitte
This is a misused function, as it was called during query cache flush, when the provider operation bits were meant to record if methods for a certain operation has already been added to the method store. Fixes #18150 Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/18151) (cherry picked from commit 20b6d85ab2b9cfa4cd29d2422d69c3e3f4db0a41)
2021-12-24permitting no/empty digest in core_obj_add_sigid for openssl-3.0Michael Baentsch
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17327)
2021-12-17ossl_provider_add_to_store: Avoid use-after-freeTomas Mraz
Avoid freeing a provider that was not up-ref-ed before. Fixes #17292 Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17295) (cherry picked from commit 33df7cbe5e38feb0cf962386bcac061c3743ecf2)
2021-11-15Hold the flag_lock when calling child callbacksMatt Caswell
Not holding the flag lock when creating/removing child providers can confuse the activation counts if the parent provider is loaded/unloaded at the same time. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17018)
2021-11-15Use a write lock during ossl_provider_find()Matt Caswell
A "find" operation on a stack can end up sorting the underlying stack. In this case it is necessary to use a "write" lock to synchronise access to the stack across multiple threads. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17018)
2021-11-15Don't bail out during provider deactivation if we don't have storeMatt Caswell
A provider may have been activated, but failed when being added to the store. At this point we still need to deactivate it. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17018)
2021-11-15Don't try and do ossl_provider_find in ossl_provider_newMatt Caswell
We leave it to the caller to confirm that the provider does not exist in the store. If it does exist then later adding it to the store will fail. It is possible that the provider could be added to the store in between the caller checking, and the caller calling ossl_provider_new. We leave it to the caller to properly handle the failure when it attempts to add the provider to the store. This is simpler than having ossl_provider_new try to handle it. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17018)
2021-11-15Don't attempt to deactive child providers if we don't need toMatt Caswell
If a provider doesn't have any child providers then there is no need to attempt to remove them - so we should not do so. This removes some potentialy thread races. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17018)
2021-08-31Refactor provider_core.c to adhere to the locking rulesMatt Caswell
The previous commit provided some guidelines and some rules for using locking in order to avoid deadlocks. This commit refactors the code in order to adhere to those guidelines and rules. Fixes #16312 Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/16469)
2021-08-31Add commentary about lock usage in provider_core.cMatt Caswell
Provide some guidelines, as well as some rules for using the locks in provider_core.c, in order to avoid the introduction of deadlocks. Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/16469)
2021-06-24Fix a race in ossl_provider_add_to_store()Matt Caswell
If two threads both attempt to load the same provider at the same time, they will first both check to see if the provider already exists. If it doesn't then they will both then create new provider objects and call the init function. However only one of the threads will be successful in adding the provider to the store. For the "losing" thread we should still return "success", but we should deinitialise and free the no longer required provider object, and return the object that exists in the store. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15854)
2021-06-24Move OPENSSL_add_builtin back into provider.cMatt Caswell
An earlier stage of the refactor in the last few commits moved this function out of provider.c because it needed access to the provider structure internals. The final version however no longer needs this so it is moved back again. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15854)
2021-06-24make struct provider_info_st a full typeMatt Caswell
Create the OSSL_PROVIDER_INFO to replace struct provider_info_st. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15854)
2021-06-24Don't skip the current provider in ossl_provider_register_child_cbMatt Caswell
This restriction was in place to avoid problems with recursive attempts to aquire the flag lock/store lock from within a provider's init function. Since those locks are no longer held when calling the init function there is no reason for the restriction any more. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15854)
2021-06-24Don't hold any locks while calling the provider init functionMatt Caswell
Previously providers were added to the store first, and then subsequently initialised. This meant that during initialisation the provider object could be shared between multiple threads and hence the locks needed to be held. However this causes problems because the provider init function is essentially a user callback and could do virtually anything. There are many API calls that could be invoked that could subsequently attempt to acquire the locks. This will fail because the locks are already held. However, now we have refactored things so that the provider is created and initialised before being added to the store. Therefore at the point of initialisation the provider object is not shared with other threads and so no locks need to be held. Fixes #15793 Fixes #15712 Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15854)
2021-06-24Only associate a provider with a store once it has been added to itMatt Caswell
This means we can distinguish providers that have been added to the store, and those which haven't yet been. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15854)
2021-06-24Merge ossl_provider_activate() and ossl_provider_activate_child()Matt Caswell
These 2 functions have become so close to each other that they may as well be just one function. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15854)
2021-06-24Set use_fallbacks to zero when we add a provider to the storeMatt Caswell
Update use_fallbacks to zero when we add a provider to the store rather than when we activate it. Its only at the point that we add it to the store that it is actually usable and visible to other threads. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15854)
2021-06-24Remove flag_couldbechildMatt Caswell
Now that a provider is no longer put into the store until after it has been activated we don't need flag_couldbechild any more. This flag was used to indicate whether a provider was eligible for conversion into a child provider or not. This was only really interesting for predefined providers that were automatically created. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15854)
2021-06-24Add a new provider to the store only after we activate itMatt Caswell
Rather than creating the provider, adding to the store and then activating it, we do things the other way around, i.e. activate first and then add to the store. This means that the activation should occur before other threads are aware of the provider. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15854)
2021-06-24Instantiate configuration supplied providers when we need themMatt Caswell
If provider specified in a config file are not "activated" then we defer instantiating the provider object until it is actually needed. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15854)
2021-06-24Instantiate user-added builtin providers when we need themMatt Caswell
Previously we created the provider object for builtin providers at the point that OPENSSL_add_builtin() was called. Instead we delay that until the provider is actually loaded. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15854)
2021-06-24Instantiate predefined providers just-in-timeMatt Caswell
Previously we instantiated all the predefined providers at the point that we create the provider store. Instead we move them to be instantiated as we need them. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15854)
2021-06-16Add various OBJ functions as callbacksMatt Caswell
This enables providers to register new OIDs in the same libcrypto instance as is used by the application. Fixes #15624 Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: Tim Hudson <tjh@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15681)
2021-06-11ossl_provider_set_module_path: Prevent potential UAFTomas Mraz
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15680)
2021-06-02crypto: remove TODOsPauli
Fixes #15451 Reviewed-by: Tim Hudson <tjh@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15539)
2021-06-01Rename also the OSSL_PROVIDER_name() functionTomas Mraz
Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-24Fix a memleak in the FIPS providerMatt Caswell
If the DRBG is used within the scope of the FIPS OSSL_provider_init function then it attempts to register a thread callback via c_thread_start. However the implementation of c_thread_start assumed that the provider's provctx was already present. However because OSSL_provider_init is still running it was actually NULL. This means the thread callback fail to work correctly and a memory leak resulted. Instead of having c_thread_start use the provctx as the callback argument we change the definition of c_thread_start to have an explicit callback argument to use. Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15278)
2021-05-20Update documentation for global properties mirroringMatt Caswell
Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15242)
2021-05-20Add a callback for providers to know about global properties changesMatt Caswell
Where a child libctx is in use it needs to know what the current global properties are. Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15242)