Skip to content
Memory corruption Disclosed report Advanced CVE-2024-11704

Double free in sec_pkcs7_decoder_start_decrypt()

A double free occurs in sec_pkcs7_decoder_start_decrypt() when an error path frees the same symmetric key twice. An attacker could potentially trigger this by causing the decryption object creation to fail, leading to memory corruption.

mozillabugs Follow

Originally disclosed on Mozilla

  • Fixed in 5 months
  • Paid in 5 months
  • Disclosed after 5 months
Text
`sec_pkcs7_decoder_start_decrypt()` (`security/nss/lib/pkcs7/p7decode.c`) calls `PK11_FreeSymKey()` twice for the same key on an error path. The issue occurs if line 538-9 fails, returning `NULL`. Line 544 then unconditionally frees `bulkkey`, the condition on line 546 is `true`, and line 549 transfers control to line 562. Line 563 then frees `bulkkey` again.

`sec_pkcs7_decoder_start_decrypt()` is linked into the FF executable, but I haven't found where FF uses it. It is definitely used by TBird for S/MIME.

Code from `FIREFOX_126_0_RELEASE`:


'''
    468: static SECStatus
    469: sec_pkcs7_decoder_start_decrypt(
    ...
    473: {
    474:     PK11SymKey *bulkkey = NULL;
    ...
    538:     decryptobj = sec_PKCS7CreateDecryptObject(bulkkey,
    539:                                               &(enccinfo->contentEncAlg));
    540: 
    541:     /*
    542:      * We are done with (this) bulkkey now.
    543:      */
    544:     PK11_FreeSymKey(bulkkey);
    545: 
    546:     if (decryptobj == NULL) {
    547:         p7dcx->error = PORT_GetError();
    548:         PORT_SetError(0);
    549:         goto no_decryption;
    550:     }
    ...
    562: no_decryption:
    563:     PK11_FreeSymKey(bulkkey);
    ...
    579: }
'''

I'm working on a POC.

The original report as published on Mozilla's Bugzilla, by mozillabugs. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the error handling path unconditionally frees a key that was already freed before checking for failure.

Impact

Could lead to memory corruption, potentially allowing code execution, though the text does not confirm exploitability and notes the function's use in Firefox is unclear.

What the attacker needed

Trigger error in decryption object creation

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A double free happens when a program releases the same piece of memory twice. This can confuse the memory manager and sometimes let an attacker run their own code. Here, a function that sets up decryption frees a key, then frees it again if an earlier step failed.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by mozillabugs

View all

41 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.