You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reproduced on Azure Linux 3.0 with SymCrypt backend, openssl 3.3.2
ASAN reports memory leaks when creating a private key from raw data with EVP_PKEY_new_raw_private_key.
strace-ing proves SymCrypt backend is used.
Building openssl 3.3.2 from source and linking against it fixed the leak, therefore pointing to SymCrypt backend involvement.
More details
I'm not sure if X25519 is fully supported here. I found microsoft/SymCrypt#43 and this, which is about adding support for multiple EdDSA variations, and it seems it hasn't been done yet.
However, I'm able to successfully create X25519 keys in a freshly created Azure Linux 3.0 container.
Questions to address
Is X25519 supported by SymCrypt? And if not, is it OK that EVP_PKEY_CTX_new_id(EVP_PKEY_X25519, NULL) succeeds?
Am I using correct/wrong OpenSSL API to create/copy the keys?
If the latter, how do I change it to avoid the leak?
Code to repro
#include <cassert>
#include <openssl/evp.h>
#include <vector>
int main()
{
const int curve_nid = EVP_PKEY_X25519;
// Generate a brand new key.
EVP_PKEY* key = EVP_PKEY_new();
auto pctx = EVP_PKEY_CTX_new_id(curve_nid, NULL);
assert(pctx != nullptr);
assert(EVP_PKEY_keygen_init(pctx) == 1);
assert(EVP_PKEY_keygen(pctx, &key) == 1);
EVP_PKEY_CTX_free(pctx);
// Copy private key bytes.
std::vector<uint8_t> raw_priv(EVP_PKEY_size(key));
size_t raw_priv_len = raw_priv.size();
EVP_PKEY_get_raw_private_key(key, raw_priv.data(), &raw_priv_len);
// Create new private key from raw bytes
// ! LEAKS MEMORY !
EVP_PKEY* another_key = EVP_PKEY_new_raw_private_key(
curve_nid, nullptr, raw_priv.data(), raw_priv.size());
// Free both.
EVP_PKEY_free(key);
EVP_PKEY_free(another_key);
// Try to force-cleanup all potential leftovers, does not mitigate the leak.
EVP_cleanup();
CRYPTO_cleanup_all_ex_data();
}
The address sanitizer output leads me to believe the leak is in the SymCrypt provider, not SymCrypt itself (https://github.com/microsoft/SymCrypt-OpenSSL). When did you first notice this leak? Was it after an upgrade?
TL;DR
EVP_PKEY_X25519
EVP_PKEY_new_raw_private_key
.strace
-ing proves SymCrypt backend is used.More details
I'm not sure if
X25519
is fully supported here. I found microsoft/SymCrypt#43 and this, which is about adding support for multiple EdDSA variations, and it seems it hasn't been done yet.However, I'm able to successfully create
X25519
keys in a freshly created Azure Linux 3.0 container.Questions to address
EVP_PKEY_CTX_new_id(EVP_PKEY_X25519, NULL)
succeeds?Code to repro
Compile (replace paths if needed):
clang file_name.cpp /usr/lib/libcrypto.so.3 /usr/lib/libstdc++.so -g -fsanitize=address
Run:
./a.out
Produces:
Strace:
The text was updated successfully, but these errors were encountered: