Closed Bug 1926256 Opened 10 months ago Closed 9 months ago

AddressSanitizer: heap-use-after-free [@ SECMOD_DestroyModule] with READ of size 8 at shutdown

Categories

(NSS :: Libraries, defect, P2)

x86_64
Linux

Tracking

(firefox-esr115 wontfix, firefox-esr128135+ fixed, firefox132 wontfix, firefox133 wontfix, firefox134 wontfix, firefox135 fixed)

RESOLVED FIXED
Tracking Status
firefox-esr115 --- wontfix
firefox-esr128 135+ fixed
firefox132 --- wontfix
firefox133 --- wontfix
firefox134 --- wontfix
firefox135 --- fixed

People

(Reporter: decoder, Assigned: jschanck)

References

Details

(4 keywords, Whiteboard: [post-critsmash-triage][adv-main135+r][adv-ESR128.7+r])

Attachments

(3 files)

The attached crash information was submitted via the ASan Nightly Reporter on mozilla-central-asan-nightly revision 133.0a1-20241015135709-https://hg.mozilla.org/mozilla-central/rev/efb1596265e9da9bbccbcbf3f4f796564780ccec.

For detailed crash information, see attachment.

Looks like a use-after-free on shutdown.

Component: General → Security

I'm marking this sec-moderate because a main process shutdown UAF doesn't seem easy to exploit.

Group: core-security → crypto-core-security
Component: Security → Security: PSM
Flags: needinfo?(jschanck)
Assignee: nobody → nobody
Component: Security: PSM → Libraries
Product: Core → NSS
Version: Trunk → unspecified

I took a quick look at calls to nssToken_Destroy and I found a double free. I'm attaching a patch, but we're really close to the end of the cycle for this NSS release, so I think we should wait until the next cycle to land it. In the mean time, we should audit other calls to nssToken_Destroy.

The get_token_objects_for_cache function constructs an array called objects. Each object in objects owns a reference to a particular token. The objects are converted, one by one, into cache entries using a function called create_object. Inside create_object, the object's token reference is dropped with a call to nssToken_Destroy(object->token).

A double free can occur if the i'th call to create_object fails. In that case, get_token_objects_for_cache will

  1. restore object j's token reference for all 0 ≤ j < i,
  2. call nssCryptokiObjectArray_Destroy(objects), which calls nssToken_Destroy(object->token) for each object in objects.

This is problematic for several reasons, but in particular it assumes that create_object only calls nssToken_Destroy(object->token) on success. However, there are two error paths in create_object that occur after the call to nssToken_Destroy. Hitting either one of these error paths will cause the token's reference count to be decremented through an invalid reference in nssCryptokiObjectArray_Destroy.

Since it is safe to call nssToken_Destroy(object->token) when object->token == NULL. We should just null out the reference immediately after calling nssToken_Destroy(object->token) in create_object. We can then remove the reference juggling in get_token_objects_for_cache completely.
`

Flags: needinfo?(jschanck)
Assignee: nobody → jschanck
Severity: critical → S2
Status: NEW → ASSIGNED
Priority: -- → P2
Status: ASSIGNED → RESOLVED
Closed: 10 months ago
Resolution: --- → FIXED
Group: crypto-core-security → core-security-release
Status: RESOLVED → REOPENED
Regressions: 1932518
Resolution: FIXED → ---
Status: REOPENED → RESOLVED
Closed: 10 months ago9 months ago
Resolution: --- → FIXED
Attachment #9440210 - Attachment description: WIP: Bug 1926256 - simplify error handling in get_token_objects_for_cache modification of token access → Bug 1926256 - fix build error from 9505f79d

A patch has been attached on this bug, which was already closed. Filing a separate bug will ensure better tracking. If this was not by mistake and further action is needed, please alert the appropriate party. (Or: if the patch doesn't change behavior -- e.g. landing a test case, or fixing a typo -- then feel free to disregard this message)

Blocks: 1936150
Flags: qe-verify-
Whiteboard: [post-critsmash-triage]
Whiteboard: [post-critsmash-triage] → [post-critsmash-triage][adv-main135+r]
Whiteboard: [post-critsmash-triage][adv-main135+r] → [post-critsmash-triage][adv-main135+r][adv-ESR128.7+r]
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: