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

Deallocator mismatch in SECITEM_ArenaDupItem()

SECITEM_ArenaDupItem() calls PORT_Free() on a SECItem that was allocated from an arena when the second allocation fails, causing a deallocator mismatch. An attacker who can trigger that allocation failure could cause a crash, potentially a double free.

mozillabugs Follow

Originally disclosed on Mozilla

  • Fixed in 17 days
  • Paid in 18 days
  • Disclosed after 17 days
Text
`SECITEM_ArenaDupItem()` (`security/nss/lib/util/secitem.c`) calls the incorrect deallocator on lines 258-61 (below) if lines 253-55 fail to allocate `to->data`. Lines 258-61 unconditionally call `PORT_Free(to)`, which is incorrect if `to` was allocated from an arena, as by lines 244-46.

Code from `FIREFOX_124_0_2_RELEASE`:

'''
235: SECItem *
236: SECITEM_ArenaDupItem(PLArenaPool *arena, const SECItem *from)
237: {
238:     SECItem *to;
239: 
240:     if (from == NULL) {
241:         return (NULL);
242:     }
243: 
244:     if (arena != NULL) {
245:         to = (SECItem *)PORT_ArenaAlloc(arena, sizeof(SECItem));
246:     } else {
247:         to = (SECItem *)PORT_Alloc(sizeof(SECItem));
248:     }
249:     if (to == NULL) {
250:         return (NULL);
251:     }
252: 
253:     if (arena != NULL) {
254:         to->data = (unsigned char *)PORT_ArenaAlloc(arena, from->len);
255:     } else {
256:         to->data = (unsigned char *)PORT_Alloc(from->len);
257:     }
258:     if (to->data == NULL) {
259:         PORT_Free(to);
260:         return (NULL);
261:     }
262: 
263:     to->len = from->len;
264:     to->type = from->type;
265:     if (to->len) {
266:         PORT_Memcpy(to->data, from->data, to->len);
267:     }
268: 
269:     return (to);
270: }
'''

Here is a debugger-based POC:

1. Start FF with `-profilemanager` and attach a debugger to it.
2. Set a BP on line 254, but disable it.
3. Click "start".
4. Load, e.g., https://www.nytimes.com
5. While it's loading, enable the BP.
6. When the BP fires, record the value in `from->len`.
7. Now replace `from->len` with `0x80000000`, which guarantees that `PORT_ArenaAlloc()` will fail.
8. Step line 254.
9. Replace `from->len` with the original value you recorded in step 6.
10. Step through line 259.
11. Proceed and watch FF crash, possibly in `arena_run_reg_dalloc()` with a  "double free?" `RELEASE_ASSERT`, and possibly elsewhere with an access violation.

This bug has existed at least since the earliest version of NSS (3.10) on https://ftp.mozilla.org/pub/security/nss/releases/ . Presumably it's an inheritance from Netscape.

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

Impact

Triggering the allocation failure could crash Firefox, possibly with a double-free assertion or an access violation.

What the attacker needed

Ability to make the second allocation fail; debugger to force the failure in the PoC

How it was found

  1. Start Firefox with a profile manager and attach a debugger.
  2. Set a breakpoint on the arena allocation line and disable it.
  3. Start Firefox and load a page.
  4. Enable the breakpoint while the page loads and note the original length when it fires.
  5. Change the length to a huge value so the arena allocation fails, step the allocation, then restore the length.
  6. Step through the free call and continue; Firefox crashes.

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.

Memory for objects can come from two places: a general heap allocator or a special arena that frees everything at once. Freeing an arena object with the general free function is like returning a library book to the wrong library; the bookkeeping breaks and the program can crash.

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.