Heap buffer over-read in [@ pk11_HandUnwrap] (pk11skey.c:2665) reachable via public API PK11_UnwrapSymKey.
Categories
(NSS :: Libraries, defect, P1)
Tracking
(nss 3.126, firefox-esr115 wontfix, firefox-esr140 affected, firefox-esr153 affected, firefox151 wontfix, firefox152 wontfix, firefox153 wontfix, firefox154 fixed)
People
(Reporter: bugmon, Assigned: beurdouche)
Details
(5 keywords, Whiteboard: [prefs-checked][adv-main154+r])
Attachments
(2 files, 1 external file, 1 obsolete file)
Heap buffer over-read in pk11_HandUnwrap (pk11skey.c:2665) reachable via public API PK11_UnwrapSymKey.
ROOT CAUSE:
In pk11_HandUnwrap() at pk11skey.c:2628, a heap buffer is allocated sized to the INPUT wrapped-key length:
outKey.data = (unsigned char *)PORT_Alloc(inKey->len);
After decryption, at pk11skey.c:2665, the output length is set to the CALLER-SUPPLIED keySize with NO bounds check against the allocation size:
outKey.len = (key_size == 0) ? len : key_size;
This SECItem is then passed to pk11_ImportSymKeyWithTempl() which calls SECITEM_CopyItem() at pk11skey.c:455, performing a memcpy of outKey.len bytes from the undersized outKey.data buffer -> heap-buffer-overflow READ.
TRIGGER CONDITIONS:
- C_UnwrapKey must fail with an error other than CKR_DEVICE_ERROR (triggers pk11_HandUnwrap fallback at pk11skey.c:2861). Easily achieved with a wrapping key that has CKA_DECRYPT=TRUE but CKA_UNWRAP=FALSE (or any PKCS#11 token that rejects the unwrap for any reason).
- C_Decrypt must succeed on the wrapped blob.
- keySize parameter > wrappedKey->len.
IMPACT:
Attacker-controlled out-of-bounds heap read of (keySize - wrappedKey->len) bytes. The over-read data is copied into symKey->data and also exposed via CKA_VALUE to the PKCS#11 module, enabling heap memory disclosure. Since keySize is fully caller-controlled (int), the over-read size is arbitrary up to INT_MAX.
REACHABILITY:
Reachable from public NSS APIs: PK11_UnwrapSymKey, PK11_UnwrapSymKeyWithFlags, PK11_UnwrapSymKeyWithFlagsPerm, PK11_PubUnwrapSymKey, PK11_PubUnwrapSymKeyWithMechanism, PK11_PubUnwrapSymKeyWithFlags, PK11_PubUnwrapSymKeyWithFlagsPerm — all of which take a caller-supplied keySize parameter that flows unchecked into pk11_HandUnwrap. Any NSS consumer that allows an attacker to influence the keySize parameter while using a token whose C_UnwrapKey can fail is affected.
ASAN CONFIRMATION:
ERROR: AddressSanitizer: heap-buffer-overflow READ of size 4096 at 0x5020000a6e60 (0 bytes after 16-byte region) in memcpy via SECITEM_CopyItem_Util -> pk11_ImportSymKeyWithTempl (pk11skey.c:455) -> pk11_HandUnwrap (pk11skey.c:2669) -> pk11_AnyUnwrapKey (pk11skey.c:2861) -> PK11_UnwrapSymKey (pk11skey.c:2877). Allocation site: PORT_Alloc in pk11_HandUnwrap (pk11skey.c:2628).
| Reporter | ||
Comment 1•7 months ago
|
||
| Reporter | ||
Comment 2•7 months ago
|
||
Updated•7 months ago
|
| Assignee | ||
Comment 4•7 months ago
|
||
| Reporter | ||
Comment 5•7 months ago
|
||
Unable to reproduce bug 2027388 using build mozilla-central 20260328200338-8e941630524a. Without a baseline, bugmon is unable to analyze this bug.
Removing bugmon keyword as no further action possible. Please review the bug and re-add the keyword for further analysis.
Updated•7 months ago
|
Updated•7 months ago
|
Updated•6 months ago
|
Comment 8•5 months ago
|
||
There is an r+ patch which didn't land and no activity in this bug for 1 week.
:rrelyea, could you have a look please?
If you still have some work to do, you can add an action "Plan Changes" in Phabricator.
For more information, please visit BugBot documentation.
| Assignee | ||
Updated•5 months ago
|
Pushed by jschanck@mozilla.com:
https://hg.mozilla.org/projects/nss/rev/504321715ea3
Add defensive check on pk11_HandUnwrap key size r=nss-reviewers,rrelyea
Comment 10•4 months ago
|
||
Updated•4 months ago
|
Comment 11•4 months ago
|
||
Updated•4 months ago
|
Updated•4 months ago
|
Comment 12•4 months ago
|
||
Pushed by jschanck@mozilla.com:
https://hg.mozilla.org/projects/nss/rev/635e02b363fe
add defensive check on pk11_HandUnwrap key size. r=bbeurdouche,nss-reviewers
Updated•4 months ago
|
Updated•4 months ago
|
Updated•2 months ago
|
Updated•24 days ago
|
Updated•4 days ago
|
Description
•