Skip to content
Memory corruption Disclosed report Advanced

Latent heap corruption on allocator mismatch in nsAuthSambaNTLM::GetNextToken()

The nsAuthSambaNTLM::GetNextToken() function allocates memory using the NSPR allocator (PR_MALLOC) but releases it with the standard C library free(), which uses a different heap. If the two heaps are distinct, this mismatch corrupts both heaps, potentially leading to memory corruption and a crash or exploitable condition.

mozillabugs Follow

Originally disclosed on Mozilla

  • Fixed in 24 days
  • Paid in 28 days
  • Disclosed after 24 days

nsAuthSambaNTLM::GetNextToken() (extensions\auth\nsAuthSambaNTLM.cpp) allocates memory on the PR heap, then frees the same memory on the global heap. This mismatch will corrupt both heaps if they are different (see https://bugzilla.mozilla.org/show_bug.cgi?id=1449355 for details).

The bugs are on lines 251 and 268, which use global |free()| instead of PR_Free(). |encoded| on line 244 is allocated by PL_Base64Encode() using PR_MALLOC(), and |buf| on line 264 is allocated by ExtractMessage() by calling PL_Base64Decode(), which then calls PR_MALLOC():

228: NS_IMETHODIMP 229: nsAuthSambaNTLM::GetNextToken(const void *inToken, 230: uint32_t inTokenLen, 231: void **outToken, 232: uint32_t outTokenLen) 233: { 234: if (!inToken) { 235: / someone wants our initial message */ 236: outToken = nsMemory::Clone(mInitialMessage, mInitialMessageLen); 237: if (!outToken) 238: return NS_ERROR_OUT_OF_MEMORY; 239: outTokenLen = mInitialMessageLen; 240: return NS_OK; 241: } 242: 243: / inToken must be a type 2 message. Get ntlm_auth to generate our response / 244: char encoded = PL_Base64Encode(static_cast<const char>(inToken), inTokenLen, nullptr); 245: if (!encoded) 246: return NS_ERROR_OUT_OF_MEMORY; 247: 248: nsCString request; 249: request.AssignLiteral("TT "); 250: request.Append(encoded); 251: free(encoded); ... 264: uint8_t buf = ExtractMessage(line, outTokenLen); 265: if (!buf) 266: return NS_ERROR_FAILURE; 267: *outToken = nsMemory::Clone(buf, *outTokenLen); 268: free(buf); ... 277: }

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

The code calls the global free() on buffers that were allocated with PR_MALLOC()/PL_Base64Encode()/PL_Base64Decode(), mixing two different allocators.

Impact

Both heaps could be corrupted, which may crash the browser or, in the worst case, be exploited for code execution.

What the attacker needed

None

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 program has to give memory back to the same 'pool' it borrowed it from. Here the code borrowed memory from one pool but returned it to a different one, which confuses the bookkeeping and can corrupt memory. That kind of corruption can crash the browser and, in the worst case, let an attacker run their own code.

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.