Skip to content
DoS Disclosed report Advanced

AddressSanitizer: stack-buffer-underflow with WRITE of size 260840 (changeable) in NSS from_montgomery

When memory allocation fails inside NSS's big-number initialisation, the error path leaves a pointer uninitialised and a later cleanup call writes through it, causing a crash. An attacker who can exhaust the process's virtual memory, for example by creating an RTCPeerConnection, can trigger a segmentation fault.

Irvan Kurniawan Follow

Originally disclosed on Mozilla

  • Fixed in 5 months
  • Paid in 5 months
  • Disclosed after 5 months
Text
Created attachment 9338852
nss_from_montgomery.patch

When running `new RTCPeerConnection()` and fill memory to exhaust the process virtual memory, it able to crash with `SIGSEGV / SI_KERNEL|0x03445c5f05bd4a5e` (address can change) on [libfreeblpriv3.so|from_montgomery ](https://searchfox.org/mozilla-central/source/security/nss/lib/freebl/ecl/ecp_256_32.c#1381).

I observe the root cause is when [`MP_CHECKOK(mp_init(&result));`](https://searchfox.org/mozilla-central/source/security/nss/lib/freebl/ecl/ecp_256_32.c#1363) initialize the variable using [`mp_init_size`](https://searchfox.org/mozilla-central/source/security/nss/lib/freebl/mpi/mpi.c#137) then on [`if ((DIGITS(mp) = s_mp_alloc(prec, sizeof(mp_digit))) == NULL)`](https://searchfox.org/mozilla-central/source/security/nss/lib/freebl/mpi/mpi.c#142) when [`s_mp_alloc(prec, sizeof(mp_digit)`](https://searchfox.org/mozilla-central/source/security/nss/lib/freebl/mpi/mpi.c#142) allocation fail, it then set [`DIGITS(mp))`](https://searchfox.org/mozilla-central/source/security/nss/lib/freebl/mpi/mpi.c#142) to `NULL` and [`return MP_MEM`](https://searchfox.org/mozilla-central/source/security/nss/lib/freebl/mpi/mpi.c#143). 

After that the `MP_CHECKOK` will `goto CLEANUP` then execute [`mp_clear(&tmp);`](https://searchfox.org/mozilla-central/source/security/nss/lib/freebl/ecl/ecp_256_32.c#1381) that crashes on `SIGSEGV / SI_KERNEL`

To trigger the `s_mp_alloc` failure scenario on AddressSanitizer, I added new modified `mp_init` function as `mp_init_test`, so only `MP_CHECKOK(mp_init(&result));` use the modified function, it change code from:
'''
if ((DIGITS(mp) = s_mp_alloc(prec, sizeof(mp_digit))) == NULL)
     return MP_MEM;
'''

To following:
'''
DIGITS(mp) = NULL;
return MP_MEM;
'''

The full code change is on attached nss_from_montgomery.patch, after the patch was applied, then compile Firefox with AddressSanitizer, afterwards on Firefox startup it will crash with `AddressSanitizer: stack-buffer-underflow` with `WRITE of size 26xxx`

The original report as published on Mozilla's Bugzilla, by Irvan Kurniawan. 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 allocation-failure path in mp_init leaves the digit pointer in an inconsistent state, and the caller's cleanup then operates on that partially initialised value.

Impact

An attacker who can exhaust the browser process's virtual memory could crash it, giving a denial of service; the report does not claim code execution.

What the attacker needed

Ability to exhaust process virtual memory; browser using NSS

How it was found

  1. Create a new RTCPeerConnection in the browser
  2. Fill memory until the process virtual memory is exhausted
  3. Observe the crash in from_montgomery inside libfreeblpriv3
  4. To reproduce under AddressSanitizer, patch mp_init so allocation failure is forced, rebuild Firefox with ASan, and start it

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.

Some programs use a helper library to do maths with very large numbers, and that library needs to reserve memory first. If reserving memory fails, the cleanup code still tries to use the half-set-up number, which points at nothing sensible, so the program crashes. Here the trigger is simply using up all the memory the browser is allowed to use.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by Irvan Kurniawan

View all

72 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.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.