Closed Bug 1465186 Opened 8 years ago Closed 8 years ago

Destruction of uninitialized pointers in sftkdb_DecryptAttribute()

Categories

(NSS :: Libraries, defect)

3.34.1
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: mozillabugs, Assigned: franziskus)

Details

(Keywords: csectype-uninitialized, reporter-external, sec-low)

Attachments

(1 external file)

In an error case, sftkdb_DecryptAttribute() (security\nss\lib\softoken\sftkpwd.c) destroys the objects pointed to by two uninitialized pointers. The bug is that line 229, below, does not initialize |ciphervalue.param| and |ciphervalue.arena|. If line 232 fails inside sftkdb_decodeCipherText() on line 141-44 (as with an OOM) it also does not initialize |ciphervalue->param| and |ciphervalue->arena|. This causes control to reach lines 244 et seq., with line 246 attempting to destroy the "object" pointed to by |ciphervalue.param| (which devolves to destroying an "arena" somewhere in hyperspace) and line 249 attempting to destroy the "arena" pointed to by |ciphervalue.arena|. 225: SECStatus 226: sftkdb_DecryptAttribute(SECItem *passKey, SECItem *cipherText, SECItem **plain) 227: { 228: SECStatus rv; 229: sftkCipherValue cipherValue; 230: 231: /* First get the cipher type */ 232: rv = sftkdb_decodeCipherText(cipherText, &cipherValue); 233: if (rv != SECSuccess) { 234: goto loser; 235: } ... 244: loser: 245: if (cipherValue.param) { 246: nsspkcs5_DestroyPBEParameter(cipherValue.param); 247: } 248: if (cipherValue.arena) { 249: PORT_FreeArena(cipherValue.arena, PR_FALSE); 250: } 251: return rv; 252: } 134: static SECStatus 135: sftkdb_decodeCipherText(SECItem *cipherText, sftkCipherValue *cipherValue) 136: { 137: PLArenaPool *arena = NULL; 138: SFTKDBEncryptedDataInfo edi; 139: SECStatus rv; 140: 141: arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); 142: if (arena == NULL) { 143: return SECFailure; 144: } 145: cipherValue->arena = NULL; 146: cipherValue->param = NULL; ... 171: } I'll attempt a POC.
Flags: needinfo?(mozillabugs)
There is also a similar bug in sftkdb_VerifyAttribute() in the same module, where |signvalue| is not initialized.
Here's a POC. Start FF, ensuring that soft-token support is enabled. Now attach a debugger to it (you might need to attach to several processes if E10S is enabled), and set a BP on line 232. Visit https://ipv.sx/u2f and click "U2F Register". When the BP fires, step into sftkdb_decodeCipherText() and skip line 141 to simulate an OOM. Step out and to line 246. Observe how |cipherValue| is uninitialized. Step into nsspkcs5_DestroyPBEParameter() and watch it attempt to destroy an "arena" somewhere in hyperspace. I got a read access-violation at address 0x10000002; you'll probably get something different.
Flags: needinfo?(mozillabugs)
Flags: sec-bounty?
(In reply to mozillabugs from comment #2) > Here's a POC. Nit: That's "Steps to Reproduce" (STR) not a POC. Useful, but not the same thing.
Maybe sec-moderate because there might be ways to make that function fail besides an unlikely-timed OOM.
(In reply to Daniel Veditz [:dveditz] from comment #3) > (In reply to mozillabugs from comment #2) > > Here's a POC. > > Nit: That's "Steps to Reproduce" (STR) not a POC. Useful, but not the same > thing. Nit noted.
Assignee: nobody → franziskuskiefer
Comment on attachment 8983336 [details] Bug 1465186 - null cipherValue pointers Martin Thomson [:mt:] has approved the revision. https://phabricator.services.mozilla.com/D1554
Attachment #8983336 - Flags: review+
Status: UNCONFIRMED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → 3.38
Group: crypto-core-security → core-security-release
I don't see any realistic way to force an OOM at exactly this point with useful uninitialized values in the cipherValue param.
Flags: sec-bounty? → sec-bounty-
Keywords: sec-moderate → sec-low
FWIW, sftkdb_DecryptAttribute() is also called during startup while loading the "NSS Internal PKCS #11 Module". You can use the same procedure as in the second paragraph of https://bugzilla.mozilla.org/show_bug.cgi?id=1465186#c2 to cause FF to use the uninitialized variables.
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: