Closed Bug 1933031 Opened 1 year ago Closed 11 months ago

Segmentation fault in SECITEM_Hash during pkcs12 processing

Categories

(NSS :: Libraries, defect, P3)

3.99

Tracking

(firefox-esr115 unaffected, firefox-esr128 unaffected, firefox133 unaffected, firefox134 wontfix, firefox135 fixed)

RESOLVED FIXED
Tracking Status
firefox-esr115 --- unaffected
firefox-esr128 --- unaffected
firefox133 --- unaffected
firefox134 --- wontfix
firefox135 --- fixed

People

(Reporter: marc, Assigned: rrelyea)

References

(Regression)

Details

(4 keywords, Whiteboard: [post-critsmash-triage][adv-main135-])

Attachments

(2 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0) Gecko/20100101 Firefox/132.0

Steps to reproduce:

I ran pk12util -l secitem_hash_pw_start.pk12 -Wstart .

This occurs with the current packages on Ubuntu 24.04.1
--> libnss3/noble,now 2:3.98-1build1 amd64 [installed]

Depending on where this function is called from it might be a security bug due to session disruption and in general availability effects.

Actual results:

It crashed in SECITEM_Hash.

(gdb) bt
#0 0x00007ffff7f822cc in SECITEM_Hash () from /lib/x86_64-linux-gnu/libnssutil3.so
#1 0x00007ffff7f6ac16 in PL_HashTableLookupConst () from /lib/x86_64-linux-gnu/libplds4.so
#2 0x00007ffff7f8bcd4 in SECOID_FindOID_Util () from /lib/x86_64-linux-gnu/libnssutil3.so
#3 0x00007ffff7f8bd9d in SECOID_FindOIDTag_Util () from /lib/x86_64-linux-gnu/libnssutil3.so
#4 0x00007ffff7f19b28 in SEC_PKCS12DecoderIterateNext () from /lib/x86_64-linux-gnu/libsmime3.so
#5 0x00005555555598cb in ?? ()
#6 0x00007ffff7be81ca in __libc_start_call_main (main=main@entry=0x555555559300, argc=argc@entry=4, argv=argv@entry=0x7fffffffdd88) at ../sysdeps/nptl/libc_start_call_main.h:58
#7 0x00007ffff7be828b in __libc_start_main_impl (main=0x555555559300, argc=4, argv=0x7fffffffdd88, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffdd78)
at ../csu/libc-start.c:360
#8 0x000055555555c4c5 in ?? ()

The crash location seems to map to:

https://github.com/servo/nss/blob/949eb9848f4fa5f83756f3ab7fdf9b0d3f20d37f/lib/util/secitem.c#L326

It looks like the *key parameter is not properly validated.

Expected results:

No crash, nice error message.

I'm pretty sure the only way to get to this functionality in Firefox is to manually import a PKCS#12 user cert. I can't see any reason a server would be messing with these, but maybe there are cases?

Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(dkeeler)
Keywords: sec-other, testcase

hg bisect tells me this was fixed by bug 1923767. In any case, I don't think Firefox could ever even run this code.

Status: NEW → RESOLVED
Closed: 1 year ago
Duplicate of bug: CVE-2024-11706
Flags: needinfo?(dkeeler)
Resolution: --- → DUPLICATE

Nevermind - this was reintroduced with bug 1930797 and the "ignore integrity" (-I) option.

Status: RESOLVED → REOPENED
No longer duplicate of bug: CVE-2024-11706
Keywords: regression
Regressed by: 1930797
Resolution: DUPLICATE → ---
Flags: needinfo?(rrelyea)

I'll take a look. The code for -I shouldn't be triggered, however, if you don't actually specify -I.

Assignee: nobody → rrelyea
Flags: needinfo?(rrelyea)

It's not failing for me on the latest builds. Is there more that needs to happen on the command line... like a password?

Flags: needinfo?(marc)

pk12util -I -l secitem_hash_pw_start.pk12
Enter password for PKCS12 file:
pk12util: PKCS12 decode not verified: SEC_ERROR_BAD_PASSWORD: The security password entered is incorrect.
pk12util: PKCS12 decode iterate bags failed: SEC_ERROR_INVALID_ARGS: security library: invalid arguments.

k12util -l secitem_hash_pw_start.pk12
Enter password for PKCS12 file:
pk12util: PKCS12 decode not verified: SEC_ERROR_BAD_PASSWORD: The security password entered is incorrect.
pk12util: PKCS12 decode not verified: SEC_ERROR_BAD_DER: security library: improperly formatted DER-encoded message.

Try -Wstart?

Yes, "start" is the password for the pkcs12 file.

Flags: needinfo?(marc)

Ah the period made the command line look like part of the filename to me.

So pk12util -l does not fail on the current build, but pk12util -I -l with the password does.
The previous fix only masked the problem (pk12util is just a utility, the underlying problem is in the pkcs12 processing code. pk12util isn't the only way to get there, applications can call the underlying pkcs12 code and wide up crashing).

I'll include a patch to make sure p12 code isn't calling through invalid pointers.
I'll also patch the secoid code to verify if we are calling with NULL pointers.

The crash now only happens in pk12util if integrity is ignored. The underlying crash, however is the result of errors in the pk12util handling. It is dereferencing pointers that can be null without checking them. This patch fixes the dereference issues as well as making SECOID_GetOID more robust.

There is a question of why errors in the cert bag looks like integrity errors. That may have been an issue with the previous patch.

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)
Status: REOPENED → RESOLVED
Closed: 1 year ago11 months ago
Resolution: --- → FIXED
Group: crypto-core-security → core-security-release

Bob, can you please set priority and severity when you have time? : ) Thanks!

Flags: needinfo?(bbeurdouche) → needinfo?(rrelyea)
Severity: -- → S4
Flags: needinfo?(rrelyea)
Priority: -- → P3
Flags: qe-verify-
Whiteboard: [post-critsmash-triage]
Whiteboard: [post-critsmash-triage] → [post-critsmash-triage][adv-main135-]

Comment 2 seemed to indicate that this bug never affected Firefox, but only NSS.
That's why this was tagged as not to be included in the Firefox release advisories.

Did you find a way to trigger this bug from Firefox prior to version 135?
If so, we'll be happy to include it after all.

Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: