AddressSanitizer: heap-use-after-free [@ SECMOD_DestroyModule] with READ of size 8 at shutdown
Categories
(NSS :: Libraries, defect, P2)
Tracking
(firefox-esr115 wontfix, firefox-esr128135+ 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.
Reporter | ||
Comment 1•10 months ago
|
||
Reporter | ||
Updated•10 months ago
|
Comment 2•10 months ago
|
||
I'm marking this sec-moderate because a main process shutdown UAF doesn't seem easy to exploit.
Updated•10 months ago
|
![]() |
||
Updated•10 months ago
|
Assignee | ||
Comment 3•10 months ago
|
||
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
- restore object j's token reference for all 0 ≤ j < i,
- call
nssCryptokiObjectArray_Destroy(objects)
, which callsnssToken_Destroy(object->token)
for each object inobjects
.
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.
`
Assignee | ||
Comment 4•10 months ago
|
||
Assignee | ||
Updated•10 months ago
|
Updated•10 months ago
|
Assignee | ||
Comment 5•10 months ago
|
||
Updated•10 months ago
|
Assignee | ||
Comment 6•9 months ago
|
||
The patch from Comment 5 was backed out of NSS 3.107 for causing Bug 1932518.
https://hg.mozilla.org/projects/nss/rev/d16826fc40d0cf4601f84030f7e4617e3eabd23d
Assignee | ||
Comment 7•9 months ago
|
||
Comment 8•9 months ago
|
||
Updated•9 months ago
|
Comment 9•9 months ago
|
||
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)
Updated•9 months ago
|
Updated•8 months ago
|
Updated•7 months ago
|
Updated•7 months ago
|
Updated•7 months ago
|
Updated•7 months ago
|
Updated•3 months ago
|
Description
•