LSan leak in WPT /WebCryptoAPI/generateKey/ test
Categories
(NSS :: Libraries, defect, P1)
Tracking
(firefox-esr60 wontfix, firefox65 wontfix, firefox66 wontfix, firefox67 fixed)
People
(Reporter: mccr8, Assigned: keeler)
References
(Blocks 2 open bugs)
Details
(Keywords: memory-leak, Whiteboard: [MemShrink:P3])
Attachments
(1 file)
Reporter | ||
Comment 1•6 years ago
|
||
Reporter | ||
Comment 2•6 years ago
|
||
I ran all of the tests in this directory individually. Three of them seem to trigger the leak, when run as follows:
./mach wpt WebCryptoAPI/generateKey/failures_RSA-OAEP.https.any.html
./mach wpt WebCryptoAPI/generateKey/failures_RSA-PSS.https.any.html
./mach wpt WebCryptoAPI/generateKey/failures_RSASSA-PKCS1-v1_5.https.any.html
Updated•6 years ago
|
Comment 4•6 years ago
|
||
The allocation comes from GenerateAsymmetricKeyTask::DoCrypto() and specifically this line:
mPrivateKey = UniqueSECKEYPrivateKey(PK11_GenerateKeyPair(
slot.get(), mMechanism, param, &pubKey, PR_FALSE, PR_FALSE, nullptr));
That line seems to be storing the result of PK11_GenerateKeyPair
in a UniqueSECKEYPrivateKey
, which is a custom UniquePtr
. Typically, you'd think that a UniquePtr
should prevent memory from leaking (but apparently doesn't in this case). Note that this custom-UniquePtr machinery allows you to provide your own deletion function, and in this case we use SECKEY_DestroyPrivateKey
, defined here:
https://searchfox.org/mozilla-central/rev/9eb30227b21e0aa40d51d9f9b08bb0b113c5fadb/security/nss/lib/cryptohi/seckey.c#240
Reporter | ||
Comment 5•6 years ago
|
||
Yeah, I'm not sure what exactly is leaking. It is a single byte allocation, leaking 38 times. My guess is we hit some error state which leaves some data structure in a partially-set up case, and then whatever cleanup method fails to clean up some single byte thing hanging off of it.
Assignee | ||
Comment 6•6 years ago
|
||
Aha - I found at least one leak at https://searchfox.org/mozilla-central/rev/9eb30227b21e0aa40d51d9f9b08bb0b113c5fadb/security/nss/lib/softoken/pkcs11c.c#4834
/* extract the exponent */
crv = sftk_Attribute2SSecItem(NULL, &pubExp, publicKey, CKA_PUBLIC_EXPONENT);
if (crv != CKR_OK)
break;
bitSize = sftk_GetLengthInBits(pubExp.data, pubExp.len);
if (bitSize < 2) {
crv = CKR_ATTRIBUTE_VALUE_INVALID;
break;
}
crv = sftk_AddAttributeType(privateKey, CKA_PUBLIC_EXPONENT,
sftk_item_expand(&pubExp));
if (crv != CKR_OK) {
PORT_Free(pubExp.data);
break;
}
rsaPriv = RSA_NewKey(public_modulus_bits, &pubExp);
PORT_Free(pubExp.data);
If we pass in an exponent with value 1, we'll break without freeing the memory pointed to by pubExp.data
.
Assignee | ||
Comment 7•6 years ago
|
||
Assignee | ||
Updated•6 years ago
|
Reporter | ||
Comment 8•6 years ago
|
||
Thanks for looking at this! If you have ASan set up, you could try deleting the file testing/web-platform/meta/WebCryptoAPI/generateKey/dir.ini and then running ./mach wpt WebCryptoAPI/generateKey/ and see if there are any leaks reported. If not, you could delete the file as part of your patch.
Assignee | ||
Comment 9•6 years ago
|
||
Ah - thanks for the pointer. Since this is an NSS change, it won't go directly into mozilla-central when this bug is closed, so I'll file a follow-up to remove that.
https://treeherder.mozilla.org/#/jobs?repo=nss-try&revision=9b518a646aacc092b81e94421c09aa9b87f2cab1
Comment 10•6 years ago
|
||
Updated•6 years ago
|
Updated•6 years ago
|
Description
•