A failed OSSL_PROVIDER_load() call disables OpenSSL implicit default
provider loading. If legacy load was attempted first and failed, no
providers would be active, causing AES, SHA, and MD5 operations to fail.

Load the default provider unconditionally first. A failure here is fatal
and returns an error. Attempt legacy load second; if it is unavailable,
log a warning and continue with default-only support.

Provider load is moved to the start of cryptodev_openssl_create() before
any device resources are allocated. There is no valid use case for a PMD
without a working default provider, so failing early avoids unnecessary
device allocation and cleanup.

On provider load failure, unload providers explicitly and return -ENOTSUP.
On device creation failure, unload via the init_error path after
cryptodev_openssl_remove(). This is needed because
cryptodev_openssl_remove() returns early with -ENODEV when no device
exists, bypassing the unload.

Rename ossl_legacy_provider_load/unload to ossl_providers_load/unload
to reflect that both default and legacy providers are managed.

Signed-off-by: Pratik Senapati <[email protected]>
---
v2:
 - Fix provider load order: default provider loaded first (always
   required), legacy loaded second (optional); v1 loaded legacy first,
   which on failure left no active providers breaking AES/SHA/MD5
 - Move provider load to start of cryptodev_openssl_create() before
   device allocation so a missing default provider fails early
 - Add ossl_providers_unload() to init_error path; needed because
   cryptodev_openssl_remove() returns -ENODEV early when no device
   exists, bypassing the unload in cryptodev_openssl_remove()
 - Rename ossl_legacy_provider_load/unload to ossl_providers_load/unload
   to reflect that both providers are now managed by these helpers
 - openssl_pmd_caps_init() call moved here from patch 1 as it logically
   belongs after provider load is complete

 drivers/crypto/openssl/rte_openssl_pmd.c | 44 ++++++++++++------------
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c 
b/drivers/crypto/openssl/rte_openssl_pmd.c
index b1ede62da2..1200f22d51 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd.c
@@ -32,24 +32,26 @@ static uint8_t cryptodev_driver_id;
 OSSL_PROVIDER *legacy;
 OSSL_PROVIDER *deflt;
 
-static void ossl_legacy_provider_load(void)
+static int
+ossl_providers_load(void)
 {
-       /* Load Multiple providers into the default (NULL) library context */
-       legacy = OSSL_PROVIDER_load(NULL, "legacy");
-       if (legacy == NULL) {
-               OPENSSL_LOG(ERR, "Failed to load Legacy provider");
-               return;
-       }
-
+       /* Load default provider first -- always required */
        deflt = OSSL_PROVIDER_load(NULL, "default");
        if (deflt == NULL) {
                OPENSSL_LOG(ERR, "Failed to load Default provider");
-               OSSL_PROVIDER_unload(legacy);
-               return;
+               return -ENOTSUP;
        }
+
+       /* Load legacy provider -- optional, non-fatal if unavailable */
+       legacy = OSSL_PROVIDER_load(NULL, "legacy");
+       if (legacy == NULL)
+               OPENSSL_LOG(WARNING, "Legacy provider not available");
+
+       return 0;
 }
 
-static void ossl_legacy_provider_unload(void)
+static void
+ossl_providers_unload(void)
 {
        OSSL_PROVIDER_unload(legacy);
        OSSL_PROVIDER_unload(deflt);
@@ -4169,6 +4171,12 @@ cryptodev_openssl_create(const char *name,
        struct rte_cryptodev *dev;
        struct openssl_private *internals;
 
+       if (ossl_providers_load() < 0) {
+               ossl_providers_unload();
+               return -ENOTSUP;
+       }
+       openssl_pmd_caps_init();
+
        dev = rte_cryptodev_pmd_create(name, &vdev->device, init_params);
        if (dev == NULL) {
                OPENSSL_LOG(ERR, "failed to create cryptodev vdev");
@@ -4199,20 +4207,12 @@ cryptodev_openssl_create(const char *name,
 
        rte_cryptodev_pmd_probing_finish(dev);
 
-       /* Load legacy provider
-        * Some algorithms are no longer available in earlier version of 
openssl,
-        * unless the legacy provider explicitly loaded. e.g. DES
-        */
-       ossl_legacy_provider_load();
-       openssl_pmd_caps_init();
-
        return 0;
 
 init_error:
-       OPENSSL_LOG(ERR, "driver %s: create failed",
-                       init_params->name);
-
+       OPENSSL_LOG(ERR, "driver %s: create failed", init_params->name);
        cryptodev_openssl_remove(vdev);
+       ossl_providers_unload();
        return -EFAULT;
 }
 
@@ -4254,7 +4254,7 @@ cryptodev_openssl_remove(struct rte_vdev_device *vdev)
        if (cryptodev == NULL)
                return -ENODEV;
 
-       ossl_legacy_provider_unload();
+       ossl_providers_unload();
 
        return rte_cryptodev_pmd_destroy(cryptodev);
 }
-- 
2.43.0

Reply via email to