AddressSanitizer: heap-use-after-free [@ lengthOfSafeChars] with READ of size 1
Categories
(Core :: JavaScript Engine, defect, P1)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox127 | --- | affected |
People
(Reporter: decoder, Unassigned)
References
(Blocks 1 open bug)
Details
(5 keywords, Whiteboard: [bugmon:update,bisect])
Attachments
(1 file)
|
10.78 KB,
text/plain
|
Details |
The following crash was found on mozilla-central revision 20240509-8f49349eeb0e (asan-opt build, ran with --fuzzing-safe --wasm-compiler=baseline+optimizing --no-asmjs --ion-pruning=on --ion-warmup-threshold=0 --ion-eager --scalar-replace-arguments --blinterp --blinterp-warmup-threshold=1 --more-compartments --ion-offthread-compile=off --gc-zeal=16,393 --baseline-warmup-threshold=100 --no-baseline ):
Backtrace:
=================================================================
==1352887==ERROR: AddressSanitizer: heap-use-after-free on address 0x50c000052300 at pc 0x55f0193e80f4 bp 0x7ffedf7da020 sp 0x7ffedf7da018
READ of size 1 at 0x50c000052300 thread T0
#0 0x55f0193e80f3 in lengthOfSafeChars /builds/worker/workspace/obj-build/dist/include/js/Printer.h:408:35
#1 0x55f0193e80f3 in js::EscapePrinter<js::Sprinter, js::StringEscape>::put(char const*, unsigned long) /builds/worker/workspace/obj-build/dist/include/js/Printer.h:427:22
#2 0x55f0193dfe10 in js::GenericPrinter::putString(JSContext*, JSString*) /js/src/vm/Printer.cpp
#3 0x55f0193e252d in QuoteString /js/src/vm/Printer.cpp:378:6
#4 0x55f0193e252d in js::QuoteString(JSContext*, JSString*, char) /js/src/vm/Printer.cpp:390:3
#5 0x55f0195e48cf in StringToSource /js/src/vm/ToSource.cpp:58:23
#6 0x55f0195e48cf in js::ValueToSource(JSContext*, JS::Handle<JS::Value>) /js/src/vm/ToSource.cpp:134:14
#7 0x55f01976bcbf in str_uneval(JSContext*, unsigned int, JS::Value*) /js/src/builtin/String.cpp:372:19
#8 0x55f018ee6671 in CallJSNative /js/src/vm/Interpreter.cpp:480:13
#9 0x55f018ee6671 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /js/src/vm/Interpreter.cpp:574:12
#10 0x55f01a210313 in js::jit::DoCallFallback(JSContext*, js::jit::BaselineFrame*, js::jit::ICFallbackStub*, unsigned int, JS::Value*, JS::MutableHandle<JS::Value>) /js/src/jit/BaselineIC.cpp:1663:10
#11 0x13d84e1ec833 (<unknown module>)
0x50c000052300 is located 0 bytes inside of 128-byte region [0x50c000052300,0x50c000052380)
freed by thread T6 (JS Helper) here:
#0 0x55f018b19fd6 in free /builds/worker/fetches/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:52:3
#1 0x55f01a0052cb in js_free /builds/worker/workspace/obj-build/dist/include/js/Utility.h:418:3
#2 0x55f01a0052cb in freeUntracked /js/src/gc/GCContext.h:117:33
#3 0x55f01a0052cb in js::gc::GCRuntime::freeFromBackgroundThread(js::AutoLockHelperThreadState&) /js/src/gc/Sweeping.cpp:479:12
#4 0x55f019f732da in js::GCParallelTask::runTask(JS::GCContext*, js::AutoLockHelperThreadState&) /js/src/gc/GCParallelTask.cpp:207:3
#5 0x55f019f73847 in js::GCParallelTask::runHelperThreadTask(js::AutoLockHelperThreadState&) /js/src/gc/GCParallelTask.cpp:189:3
#6 0x55f01921a241 in js::GlobalHelperThreadState::runTaskLocked(js::HelperThreadTask*, js::AutoLockHelperThreadState&) /js/src/vm/HelperThreads.cpp:1730:9
#7 0x55f019219dd4 in js::GlobalHelperThreadState::runOneTask(js::AutoLockHelperThreadState&) /js/src/vm/HelperThreads.cpp:1699:5
#8 0x55f019219a65 in JS::RunHelperThreadTask() /js/src/vm/HelperThreads.cpp:1686:23
#9 0x55f01922ac66 in js::HelperThread::threadLoop(js::InternalThreadPool*) /js/src/vm/InternalThreadPool.cpp:287:7
#10 0x55f01922a86e in js::HelperThread::ThreadMain(js::InternalThreadPool*, js::HelperThread*) /js/src/vm/InternalThreadPool.cpp:228:11
#11 0x55f01924bcab in callMain<0UL, 1UL> /js/src/threading/Thread.h:228:5
#12 0x55f01924bcab in js::detail::ThreadTrampoline<void (&)(js::InternalThreadPool*, js::HelperThread*), js::InternalThreadPool*&, js::HelperThread*>::Start(void*) /js/src/threading/Thread.h:217:11
#13 0x55f018b1671a in asan_thread_start(void*) /builds/worker/fetches/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:225:31
previously allocated by thread T0 here:
#0 0x55f018b1a27e in malloc /builds/worker/fetches/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:69:3
#1 0x55f0195b1e91 in js_arena_malloc /builds/worker/workspace/obj-build/dist/include/js/Utility.h:370:10
#2 0x55f0195b1e91 in js_pod_arena_malloc<unsigned char> /builds/worker/workspace/obj-build/dist/include/js/Utility.h:586:26
#3 0x55f0195b1e91 in maybe_pod_arena_malloc<unsigned char> /js/src/vm/MallocProvider.h:57:12
#4 0x55f0195b1e91 in pod_arena_malloc<unsigned char> /js/src/vm/MallocProvider.h:109:12
#5 0x55f0195b1e91 in AllocCharsForFlatten<unsigned char> /js/src/vm/StringType.cpp:621:20
#6 0x55f0195b1e91 in JSLinearString* JSRope::flattenInternal<(JSRope::UsingBarrier)0, unsigned char>(JSRope*) /js/src/vm/StringType.cpp:972:10
#7 0x55f01958f25b in flattenInternal<(JSRope::UsingBarrier)0> /js/src/vm/StringType.cpp:873:10
#8 0x55f01958f25b in flattenInternal /js/src/vm/StringType.cpp:864:10
#9 0x55f01958f25b in JSRope::flatten(JSContext*) /js/src/vm/StringType.cpp:851:25
#10 0x55f0192588ee in ensureLinear /js/src/vm/StringType.h:2097:46
#11 0x55f0192588ee in js::AtomizeString(JSContext*, JSString*) /js/src/vm/JSAtomUtils.cpp:714:35
#12 0x55f018ffa71e in js::HashableValue::setValue(JSContext*, JS::Handle<JS::Value>) /js/src/builtin/MapObject.cpp:59:21
#13 0x55f0190054d9 in setValue /js/src/builtin/MapObject.h:67:47
#14 0x55f0190054d9 in has /js/src/builtin/MapObject.cpp:934:10
#15 0x55f0190054d9 in js::MapObject::has_impl(JSContext*, JS::CallArgs const&) /js/src/builtin/MapObject.cpp:945:7
#16 0x55f018fff288 in CallNonGenericMethod<&js::MapObject::is, &js::MapObject::has_impl> /builds/worker/workspace/obj-build/dist/include/js/CallNonGenericMethod.h:103:12
#17 0x55f018fff288 in js::MapObject::has(JSContext*, unsigned int, JS::Value*) /js/src/builtin/MapObject.cpp:955:10
#18 0x55f018ee6671 in CallJSNative /js/src/vm/Interpreter.cpp:480:13
#19 0x55f018ee6671 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /js/src/vm/Interpreter.cpp:574:12
#20 0x55f01a210313 in js::jit::DoCallFallback(JSContext*, js::jit::BaselineFrame*, js::jit::ICFallbackStub*, unsigned int, JS::Value*, JS::MutableHandle<JS::Value>) /js/src/jit/BaselineIC.cpp:1663:10
#21 0x13d84e1ec833 (<unknown module>)
#22 0x13d84e1f1b25 (<unknown module>)
#23 0x13d84e1f3e13 (<unknown module>)
#24 0x13d84e1ea4e5 (<unknown module>)
#25 0x55f01aaea17f in EnterJit /js/src/jit/Jit.cpp:115:5
#26 0x55f01aaea17f in js::jit::MaybeEnterJit(JSContext*, js::RunState&) /js/src/jit/Jit.cpp:261:10
#27 0x55f018ee509d in js::RunScript(JSContext*, js::RunState&) /js/src/vm/Interpreter.cpp:442:32
#28 0x55f018ee683a in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /js/src/vm/Interpreter.cpp:606:13
#29 0x55f01a210313 in js::jit::DoCallFallback(JSContext*, js::jit::BaselineFrame*, js::jit::ICFallbackStub*, unsigned int, JS::Value*, JS::MutableHandle<JS::Value>) /js/src/jit/BaselineIC.cpp:1663:10
#30 0x13d84e1ec833 (<unknown module>)
#31 0x13d84e1f1b25 (<unknown module>)
#32 0x13d84e1f3d5c (<unknown module>)
#33 0x13d84e1ea4e5 (<unknown module>)
#34 0x55f01aaea17f in EnterJit /js/src/jit/Jit.cpp:115:5
#35 0x55f01aaea17f in js::jit::MaybeEnterJit(JSContext*, js::RunState&) /js/src/jit/Jit.cpp:261:10
#36 0x55f018ee509d in js::RunScript(JSContext*, js::RunState&) /js/src/vm/Interpreter.cpp:442:32
#37 0x55f018ee683a in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /js/src/vm/Interpreter.cpp:606:13
#38 0x55f018ee8906 in InternalCall /js/src/vm/Interpreter.cpp:641:10
#39 0x55f018ee8906 in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>, js::CallReason) /js/src/vm/Interpreter.cpp:673:8
#40 0x55f019298241 in js::fun_apply(JSContext*, unsigned int, JS::Value*) /js/src/vm/JSFunction.cpp:1105:10
#41 0x55f018ee6671 in CallJSNative /js/src/vm/Interpreter.cpp:480:13
#42 0x55f018ee6671 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /js/src/vm/Interpreter.cpp:574:12
#43 0x55f01a210313 in js::jit::DoCallFallback(JSContext*, js::jit::BaselineFrame*, js::jit::ICFallbackStub*, unsigned int, JS::Value*, JS::MutableHandle<JS::Value>) /js/src/jit/BaselineIC.cpp:1663:10
#44 0x13d84e1ec833 (<unknown module>)
#45 0x13d84e1f1b25 (<unknown module>)
Thread T6 (JS Helper) created by T0 here:
#0 0x55f018affebd in pthread_create /builds/worker/fetches/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:237:3
#1 0x55f01994861c in js::Thread::create(void* (*)(void*), void*) /js/src/threading/posix/PosixThread.cpp:57:7
#2 0x55f01922a6a9 in bool js::Thread::init<void (&)(js::InternalThreadPool*, js::HelperThread*), js::InternalThreadPool*&, js::HelperThread*>(void (&)(js::InternalThreadPool*, js::HelperThread*), js::InternalThreadPool*&, js::HelperThread*&&) /js/src/threading/Thread.h:90:16
#3 0x55f0192299c2 in init /js/src/vm/InternalThreadPool.cpp:218:17
#4 0x55f0192299c2 in js::InternalThreadPool::ensureThreadCount(unsigned long, js::AutoLockHelperThreadState&) /js/src/vm/InternalThreadPool.cpp:133:29
#5 0x55f0192296e1 in js::InternalThreadPool::Initialize(unsigned long, js::AutoLockHelperThreadState&) /js/src/vm/InternalThreadPool.cpp:112:18
#6 0x55f01920a123 in js::GlobalHelperThreadState::ensureInitialized() /js/src/vm/HelperThreads.cpp:805:10
#7 0x55f0194b17cd in JSRuntime::init(JSContext*, unsigned int) /js/src/vm/Runtime.cpp:182:32
#8 0x55f019284e06 in js::NewContext(unsigned int, JSRuntime*) /js/src/vm/JSContext.cpp:185:17
#9 0x55f018b6f90c in main /js/src/shell/js.cpp:11888:25
#10 0x7fc97f910082 in __libc_start_main /build/glibc-wuryBv/glibc-2.31/csu/../csu/libc-start.c:308:16
SUMMARY: AddressSanitizer: heap-use-after-free /builds/worker/workspace/obj-build/dist/include/js/Printer.h:408:35 in lengthOfSafeChars
Shadow bytes around the buggy address:
0x50c000052200: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
0x50c000052280: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa
=>0x50c000052300:[fd]fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x50c000052380: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
0x50c000052400: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
This crash does not reproduce, but I was hoping the uaf trace is enough to find the issue. Could be related to parallel GC? would also be great if we could find the right ingredients to reproduce so we can adjust fuzzing.
| Reporter | ||
Comment 1•2 years ago
|
||
Updated•2 years ago
|
Comment 2•2 years ago
|
||
Unable to reproduce bug 1896253 using build mozilla-central 20240509212246-8f49349eeb0e. Without a baseline, bugmon is unable to analyze this bug.
Removing bugmon keyword as no further action possible. Please review the bug and re-add the keyword for further analysis.
Comment 3•2 years ago
|
||
May be related to other string UAF bugs we've seen recently.
No STR makes this hard to action.
Comment 4•2 years ago
|
||
I agree with Jon, the report tells us roughly how the String got created as a value of a Map object and how it is last used in str_uneval, but not what caused it to become non-rooted at one point, which made it a candidate for garbage collection.
Steve, would it be easy to instrument the rooting analysis to highlight all lines where non-rooted values are being assigned to rooted values, as well as all lines where rooted values are taken without taking care of the previously rooted-status. I presume there are many legitimate cases such as in noGc scopes, returned values, allocations, where these might make sense, and that this would be a huge task to add most of them to some allow-list. However, maybe we could identify that a value is coming from a non-traced / non-rooted location when it is assigned, and bubble up to what caused it to be non-traced / non-rooted.
Comment 5•2 years ago
|
||
As Jon mentioned privately, this bug sounds similar to Bug 1890909.
Alternatively, I suggest that based on steve answers, we either:
- If we have some good insight in what might be causing, we might want to try to hypothetically fix it.
- We have a way to improve the situation around what might be rooted and marked at the same time? Either statically or dynamically.
- Or we mark this bug as stalled, as it does not have a good reproducing test case that we would be certain to fix.
Comment 6•2 years ago
|
||
The odds are very good that this is one of the other recently fixed string UAFs (bug 1890909, bug 1895055, bug 1894428). Bugs 1895055 and 1894428 are unlikely, since there's no AutoStableStringChars to blame here. Bug 1890909 can create dangling string pointers that will be UAF at a random time later, so it would explain this one.
(In reply to Nicolas B. Pierron [:nbp] from comment #4)
I agree with Jon, the report tells us roughly how the String got created as a value of a Map object and how it is last used in
str_uneval, but not what caused it to become non-rooted at one point, which made it a candidate for garbage collection.
That's probably not what's happening, though. Outright rooting problems are very rare, with the hazard analysis checking them. Probably what's happening is that all JSStrings are being properly kept alive, but there are a couple of ways for their character data to be freed: either because they were deduplicated during a nursery GC, or they were replaced with an AtomRef and their previous chars are (incorrectly) believed to be no longer needed.
Steve, would it be easy to instrument the rooting analysis to highlight all lines where non-rooted values are being assigned to rooted values, as well as all lines where rooted values are taken without taking care of the previously rooted-status. I presume there are many legitimate cases such as in noGc scopes, returned values, allocations, where these might make sense, and that this would be a huge task to add most of them to some allow-list. However, maybe we could identify that a value is coming from a non-traced / non-rooted location when it is assigned, and bubble up to what caused it to be non-traced / non-rooted.
Interesting idea, but it would be a huge list and I doubt it would catch the problem here. The problem here is with unrooted (unrootable, in fact) types (char* aka Latin1Char*, and char16_t* aka TwoByteChar*). Two hypothetical analyses: (1) detect anywhere a chars pointer is extracted and taint its dataflow, and (2) some way to prove that a chars pointer that you're about to free cannot be referenced by anything live. (All 3 of the above bugs are #2. Bug 1890909 loses the bit that tells us the chars could be referenced elsewhere. Bug 1895055, depending how you look at it, either fails to set the bit, or holds onto the wrong JSString — an example of breaking #1. Bug 1894428 fails to set the bit.)
Comment 7•2 years ago
|
||
(In reply to Steve Fink [:sfink] [:s:] from comment #6)
[…] The problem here is with unrooted (unrootable, in fact) types (char* aka Latin1Char*, and char16_t* aka TwoByteChar*). Two hypothetical analyses: (1) detect anywhere a chars pointer is extracted and taint its dataflow, and (2) some way to prove that a chars pointer that you're about to free cannot be referenced by anything live. (All 3 of the above bugs are #2. Bug 1890909 loses the bit that tells us the chars could be referenced elsewhere. Bug 1895055, depending how you look at it, either fails to set the bit, or holds onto the wrong JSString — an example of breaking #1. Bug 1894428 fails to set the bit.)
Should we introduce a BorrowedCharPtr<CharT> to make these issues easier to track by the rooting analysis?
Such type would remain valid across GC if it is created from a non-moving type and if the initial value that they are borrowed from are still rooted.
Updated•1 year ago
|
Comment 8•8 months ago
|
||
(In reply to Nicolas B. Pierron [:nbp] from comment #7)
Should we introduce a
BorrowedCharPtr<CharT>to make these issues easier to track by the rooting analysis?
Such type would remain valid across GC if it is created from a non-moving type and if the initial value that they are borrowed from are still rooted.
Oops, I never saw this question.
I tried doing that once. At least in the case I was considering, it didn't really work. The pointer was passed to lots of different things as a char* (eg stdlib functions or our custom equivalents) directly or part of a Span<char*> or whatever, so you'd either have to discard the protection constantly, or duplicate tons of code to accept the wrapped type.
Description
•