AddressSanitizer: heap-use-after-free gfx/thebes/gfxFontEntry.cpp in ForgetHashEntry after calloc failure on hb_object_create
Categories
(Core :: Graphics: Text, defect)
Tracking
()
People
(Reporter: sourc7, Assigned: jfkthame)
Details
(Keywords: csectype-uaf, reporter-external, sec-moderate, Whiteboard: [reporter-external] [client-bounty-form] [verif?] [adv-main126+])
Attachments
(6 files)
On hb_blob_create_or_fail
when the hb_object_create<hb_blob_t>
calloc return nullptr, after user_data
is freed, the user_data
able to reused by ForgetHashEntry
code.
Steps to reproduce
- Apply attached hb-blob-create-or-fail.patch
- Compile Firefox with AddressSanitizer
- Visit attached testcase-for-hb-blob-patch.html
- Firefox crashed with AddressSanitizer: heap-use-after-free
Reporter | ||
Comment 1•9 months ago
|
||
Reporter | ||
Comment 2•9 months ago
|
||
Updated•9 months ago
|
Comment 3•9 months ago
|
||
The jemalloc we use in Firefox is infallible by default. It looks like this allocation is done by calloc. glandium, am I right in thinking that calloc will never return null? Thanks. Though maybe other people build Firefox with other allocators.
Comment 4•9 months ago
|
||
Jemalloc is not infallible. moz_malloc/moz_calloc are.
Comment 5•9 months ago
|
||
That was moz_xmalloc/moz_xcalloc. https://searchfox.org/mozilla-central/rev/1e743db12971e365d1f8fc04c0c52ed55c01494b/memory/mozalloc/mozalloc.h#78-80
Updated•9 months ago
|
Assignee | ||
Comment 6•9 months ago
|
||
While this is a valid bug, I think the real-world risk here must be pretty low. Note that what's being allocated here is the hb_blob_t
struct, which is just 48 bytes (not a possibly-large block with an attacker-controlled size). So if the calloc
here does fail, we must be on the very edge of memory exhaustion. In that case it's likely that within moments, an "infallible" allocation attempt is going to terminate the process anyway.
Still, we clearly need to handle the potential failure here more correctly. Or we could switch harfbuzz to use our infallible moz_x*
functions and avoid the issue.
Assignee | ||
Comment 7•9 months ago
|
||
Assignee | ||
Comment 8•9 months ago
|
||
I haven't verified this with a local build yet, but if I'm reading the code right, I think all that's needed is to ensure we clear the mSharedBlobData
pointer in the failure case. I'll try to confirm this on my Linux machine in a while.
Irvan, if you're able to apply the above patch and check whether it resolves the issue for you, that would be great. Thanks!
Assignee | ||
Comment 9•9 months ago
|
||
Ok, in a local ASAN build I confirmed that the patch resolves the issue for me. (Further confirmation would still be welcome.)
Updated•9 months ago
|
Comment 10•9 months ago
|
||
I'll mark it sec-moderate because it sounds difficult to actually exploit.
Comment 11•9 months ago
|
||
Reporter | ||
Comment 12•9 months ago
|
||
(In reply to Jonathan Kew [:jfkthame] from comment #8)
I haven't verified this with a local build yet, but if I'm reading the code right, I think all that's needed is to ensure we clear the
mSharedBlobData
pointer in the failure case. I'll try to confirm this on my Linux machine in a while.Irvan, if you're able to apply the above patch and check whether it resolves the issue for you, that would be great. Thanks!
Thanks Jonathan for the patch, after added mSharedBlobData = nullptr;
above return hb_blob_reference(mBlob);
then re-compile the Firefox ASan, I confirm that this solves the problem. Thanks!
Comment 13•9 months ago
|
||
Comment 14•9 months ago
|
||
:jfkthame can you attach a beta uplift request on this when ready. Is this something we want to uplift to ESR115?
Assignee | ||
Comment 15•9 months ago
|
||
I think it would be fine to uplift to ESR, in that the patch carries no significant regression risk; but I also think the issue is likely so hard to exploit (reaching this particular small-allocation failure, without OOM-crashing the process) that the real-world risk is minimal. So not sure it's worth touching ESR here...?
Assignee | ||
Comment 16•9 months ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D208983
Updated•9 months ago
|
Comment 17•9 months ago
|
||
beta Uplift Approval Request
- User impact if declined: potential UAF after a malloc() failure
- Code covered by automated testing: no
- Fix verified in Nightly: yes
- Needs manual QE test: no
- Steps to reproduce for manual QE testing: n/a
- Risk associated with taking this patch: minimal
- Explanation of risk level: trivial - clearing a pointer on error
- String changes made/needed: none
- Is Android affected?: yes
Updated•9 months ago
|
Updated•9 months ago
|
Comment 18•9 months ago
|
||
uplift |
Updated•9 months ago
|
Updated•9 months ago
|
Updated•9 months ago
|
Updated•9 months ago
|
Comment 19•9 months ago
|
||
Updated•9 months ago
|
Updated•8 months ago
|
Updated•5 months ago
|
Description
•