Closed Bug 1838197 Opened 2 years ago Closed 2 years ago

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

Categories

(NSS :: Libraries, defect, P2)

Tracking

(firefox-esr115 wontfix, firefox119 fixed)

RESOLVED FIXED
Tracking Status
firefox-esr115 --- wontfix
firefox119 --- fixed

People

(Reporter: sourc7, Unassigned)

References

Details

(4 keywords, Whiteboard: [fixed by 1615555][reporter-external] [client-bounty-form] [verif?])

Attachments

(4 files)

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 .

I observe the root cause is when MP_CHECKOK(mp_init(&result)); initialize the variable using mp_init_size then on if ((DIGITS(mp) = s_mp_alloc(prec, sizeof(mp_digit))) == NULL) when s_mp_alloc(prec, sizeof(mp_digit) allocation fail, it then set DIGITS(mp)) to NULL and return MP_MEM.

After that the MP_CHECKOK will goto CLEANUP then execute mp_clear(&tmp); 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

Flags: sec-bounty?
Summary: AddressSanitizer: stack-buffer-underflow with write of size 260840 (changeable) in NSS from_montgomery → AddressSanitizer: stack-buffer-underflow with WRITE of size 260840 (changeable) in NSS from_montgomery
Duplicate of this bug: 1835763
No longer duplicate of this bug: 1835763
Assignee: nobody → nobody
Group: firefox-core-security → crypto-core-security
Component: Security → Libraries
Product: Firefox → NSS
Version: unspecified → other

The severity field is not set for this bug.
:beurdouche, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(bbeurdouche)
Flags: needinfo?(bbeurdouche)
Flags: needinfo?(bbeurdouche)

John, can you please check priority and severity on this when you have a min ?

Severity: -- → S3
Flags: needinfo?(jschanck)
Priority: -- → P2

Now that Bug 1615555 has landed, ecp_256_32.c is all dead code. We could fix it on ESR, but I think it's minor enough to WONTFIX.

Status: NEW → RESOLVED
Closed: 2 years ago
Flags: needinfo?(jschanck)
Flags: needinfo?(bbeurdouche)
Resolution: --- → WONTFIX

Since this is a security bug it's better to track the resolution as "FIXED" even though the patch was not in this bug. If bug 1615555 was specifically fixing this issue we could call it a DUPLICATE, but that isn't appropriate here. It's worth noting that although fixing this bug might be a "by-product" of landing bug 1615555 landing, it's not an "accidental" one: the main impetus for adopting the HACL* versions is correctness

WONTFIX for ESR sounds right. Adopting rewrites is usually out of scope for ESR, and the narrow conditions of this issue make it unlikely to be worth exploiting against the ESR population.

Depends on: 1615555
Flags: sec-bounty? → sec-bounty+
Resolution: WONTFIX → FIXED
Whiteboard: [reporter-external] [client-bounty-form] [verif?] → [fixed by 161555][reporter-external] [client-bounty-form] [verif?]
Group: crypto-core-security → core-security-release
Group: core-security-release
Whiteboard: [fixed by 161555][reporter-external] [client-bounty-form] [verif?] → [fixed by 1615555][reporter-external] [client-bounty-form] [verif?]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: