Closed Bug 1481093 Opened 6 years ago Closed 6 years ago

Crash [@ js::NativeObject::hasAllFlags] or Assertion failure: getElementsHeader()->initializedLength == getElementsHeader()->capacity, at /vm/NativeObject.h:545 with TypedObject

Categories

(Core :: JavaScript Engine, defect)

x86_64
Linux
defect
Not set
critical

Tracking

()

VERIFIED FIXED
mozilla63
Tracking Status
firefox-esr52 --- wontfix
firefox-esr60 62+ fixed
firefox61 --- wontfix
firefox62 + fixed
firefox63 + verified

People

(Reporter: decoder, Assigned: jonco)

References

Details

(4 keywords, Whiteboard: [jsbugmon:update,ignore][adv-main62+][adv-esr60.2+])

Crash Data

Attachments

(1 file)

The following testcase crashes on mozilla-central revision b3e7de2df93d (build with --enable-posix-nspr-emulation --enable-valgrind --enable-gczeal --disable-tests --disable-profiling --enable-debug --enable-optimize, run with --fuzzing-safe --ion-offthread-compile=off):

v = new new TypedObject.StructType({
    f: TypedObject.Any
})
gczeal(14);
var lfOffThreadGlobal = newGlobal();


Backtrace:

received signal SIGSEGV, Segmentation fault.
js::NativeObject::hasAllFlags (this=this@entry=0x7ffff4dc3080, flags=js::BaseShape::NOT_EXTENSIBLE) at js/src/vm/NativeObject.h:801
#0  js::NativeObject::hasAllFlags (this=this@entry=0x7ffff4dc3080, flags=js::BaseShape::NOT_EXTENSIBLE) at js/src/vm/NativeObject.h:801
#1  0x00000000004d7919 in js::NativeObject::isExtensible (this=0x7ffff4dc3080) at js/src/vm/NativeObject.h:808
#2  js::NativeObject::getDenseInitializedLength (this=0x7ffff4dc3080) at js/src/vm/NativeObject.h:544
#3  0x00000000008df1b8 in js::StructTypeDescr::fieldCount (this=0x7ffff4dc5920) at js/src/builtin/TypedObject.cpp:1040
#4  visitReferences<(anonymous namespace)::MemoryTracingVisitor> (descr=..., mem=0x7ffff4dbe050 "", visitor=...) at js/src/builtin/TypedObject.cpp:2743
#5  0x00000000008df7de in js::TypeDescr::traceInstances (length=1, mem=0x7ffff4dbe050 "", trace=0x7fffffffae68, this=0x7ffff4dc5920) at js/src/builtin/TypedObject.cpp:2878
#6  js::InlineTypedObject::obj_trace (trc=0x7fffffffae68, object=0x7ffff4dbe040) at js/src/builtin/TypedObject.cpp:2129
#7  0x0000000000bc7b53 in js::Class::doTrace (this=<optimized out>, obj=0x7ffff4dbe040, trc=0x7fffffffae68) at dist/include/js/Class.h:893
#8  JSObject::traceChildren (this=this@entry=0x7ffff4dbe040, trc=trc@entry=0x7fffffffae68) at js/src/vm/JSObject.cpp:3955
#9  0x0000000000f529ce in UpdateCellPointers<JSObject> (cell=0x7ffff4dbe040, trc=0x7fffffffae60) at js/src/gc/GC.cpp:2569
#10 UpdateArenaPointersTyped<JSObject> (trc=trc@entry=0x7fffffffae60, arena=<optimized out>) at js/src/gc/GC.cpp:2577
#11 0x0000000000f5c828 in UpdateArenaPointers (arena=0x7ffff4dbe000, trc=0x7fffffffae60) at js/src/gc/GC.cpp:2593
#12 js::gc::UpdatePointersTask::updateArenas (this=this@entry=0x7fffffffb070) at js/src/gc/GC.cpp:2715
#13 0x0000000000f5cdf4 in js::gc::UpdatePointersTask::run (this=0x7fffffffb070) at js/src/gc/GC.cpp:2725
#14 0x0000000000b86d55 in js::GCParallelTask::runTask (this=0x7fffffffb070) at js/src/gc/GCParallelTask.h:130
#15 js::GCParallelTask::runFromMainThread (this=this@entry=0x7fffffffb070, rt=<optimized out>) at js/src/vm/HelperThreads.cpp:1577
#16 0x0000000000f34bed in js::gc::GCRuntime::updateCellPointers (this=this@entry=0x7ffff5f196d8, zone=zone@entry=0x7ffff5f79000, kinds=..., bgTaskCount=bgTaskCount@entry=4) at js/src/gc/GC.cpp:2801
#17 0x0000000000f4e65d in js::gc::GCRuntime::updateAllCellPointers (this=this@entry=0x7ffff5f196d8, trc=trc@entry=0x7fffffffb420, zone=zone@entry=0x7ffff5f79000) at js/src/gc/GC.cpp:2885
#18 0x0000000000f59db2 in js::gc::GCRuntime::updateZonePointersToRelocatedCells (this=this@entry=0x7ffff5f196d8, zone=zone@entry=0x7ffff5f79000) at js/src/gc/GC.cpp:2918
#19 0x0000000000f69159 in js::gc::GCRuntime::compactPhase (this=this@entry=0x7ffff5f196d8, reason=reason@entry=JS::gcreason::DEBUG_GC, sliceBudget=..., session=...) at js/src/gc/GC.cpp:6767
#20 0x0000000000f69de2 in js::gc::GCRuntime::incrementalCollectSlice (this=this@entry=0x7ffff5f196d8, budget=..., reason=reason@entry=JS::gcreason::DEBUG_GC, session=...) at js/src/gc/GC.cpp:7272
#21 0x0000000000f6b04e in js::gc::GCRuntime::gcCycle (this=this@entry=0x7ffff5f196d8, nonincrementalByAPI=nonincrementalByAPI@entry=true, budget=..., reason=reason@entry=JS::gcreason::DEBUG_GC) at js/src/gc/GC.cpp:7554
#22 0x0000000000f6b7dd in js::gc::GCRuntime::collect (this=this@entry=0x7ffff5f196d8, nonincrementalByAPI=nonincrementalByAPI@entry=true, budget=..., reason=reason@entry=JS::gcreason::DEBUG_GC) at js/src/gc/GC.cpp:7728
#23 0x0000000000f6bba9 in js::gc::GCRuntime::gc (this=this@entry=0x7ffff5f196d8, gckind=gckind@entry=GC_SHRINK, reason=reason@entry=JS::gcreason::DEBUG_GC) at js/src/gc/GC.cpp:7807
#24 0x0000000000f6e2c9 in js::gc::GCRuntime::runDebugGC (this=this@entry=0x7ffff5f196d8) at js/src/gc/GC.cpp:8313
#25 0x0000000000ef7d05 in js::gc::GCRuntime::gcIfNeededAtAllocation (this=0x7ffff5f196d8, cx=cx@entry=0x7ffff5f17000) at js/src/gc/Allocator.cpp:314
#26 0x0000000000f07618 in js::gc::GCRuntime::checkAllocatorState<(js::AllowGC)1> (this=<optimized out>, cx=cx@entry=0x7ffff5f17000, kind=kind@entry=js::gc::AllocKind::SHAPE) at js/src/gc/Allocator.cpp:275
#27 0x0000000000f07e23 in js::Allocate<js::Shape, (js::AllowGC)1> (cx=cx@entry=0x7ffff5f17000) at js/src/gc/Allocator.cpp:224
#28 0x0000000000cb4227 in js::Shape::new_ (nfixed=0, other=..., cx=0x7ffff5f17000) at js/src/vm/Shape-inl.h:111
#29 js::PropertyTree::inlinedGetChild (this=0x7ffff4a5dac8, cx=<optimized out>, cx@entry=0x7ffff5f17000, parent=<optimized out>, parent@entry=0x7ffff4db2650, child=child@entry=...) at js/src/vm/Shape.cpp:1753
#30 0x0000000000cba390 in js::NativeObject::getChildDataProperty (cx=0x7ffff5f17000, obj=obj@entry=..., parent=parent@entry=..., child=child@entry=...) at js/src/vm/Shape.cpp:346
#31 0x0000000000c9b570 in js::NativeObject::addDataPropertyInternal (cx=<optimized out>, cx@entry=0x7ffff5f17000, obj=obj@entry=..., id=..., id@entry=..., slot=slot@entry=16777215, attrs=attrs@entry=0, table=<optimized out>, entry=<optimized out>, keep=...) at js/src/vm/Shape.cpp:624
#32 0x0000000000803fd4 in js::NativeObject::addDataProperty (cx=0x7ffff5f17000, obj=..., id=..., slot=16777215, attrs=0) at js/src/vm/Shape-inl.h:400
#33 0x0000000000c31ada in AddOrChangeProperty<(IsAddOrChange)0> (cx=0x7ffff5f17000, obj=..., id=..., desc=...) at js/src/vm/NativeObject.cpp:1425
#34 0x0000000000c331b1 in js::NativeDefineProperty (cx=cx@entry=0x7ffff5f17000, obj=..., id=..., id@entry=..., desc_=..., result=...) at js/src/vm/NativeObject.cpp:1703
#35 0x0000000000bd3b85 in js::DefineDataProperty (cx=cx@entry=0x7ffff5f17000, obj=..., id=..., value=..., attrs=<optimized out>, result=...) at js/src/vm/JSObject.cpp:2832
#36 0x0000000000bd3d8b in js::DefineDataProperty (cx=0x7ffff5f17000, obj=..., id=..., value=..., attrs=<optimized out>) at js/src/vm/JSObject.cpp:2873
#37 0x0000000000bd4144 in DefineFunctionFromSpec (intrinsic=js::NotIntrinsic, flags=0, fs=0x20b8c28 <object_methods+360>, obj=..., cx=<optimized out>) at js/src/vm/JSObject.cpp:2967
#38 js::DefineFunctions (cx=cx@entry=0x7ffff5f17000, obj=..., fs=0x20b8c28 <object_methods+360>, fs@entry=0x20b8ac0 <object_methods>, intrinsic=intrinsic@entry=js::NotIntrinsic) at js/src/vm/JSObject.cpp:2975
#39 0x00000000009fe5b0 in JS_DefineFunctions (cx=0x7ffff5f17000, obj=..., fs=0x20b8ac0 <object_methods>) at js/src/jsapi.cpp:3713
#40 0x0000000000babc0f in js::GlobalObject::resolveConstructor (cx=<optimized out>, cx@entry=0x7ffff5f17000, global=global@entry=..., key=key@entry=JSProto_Object) at js/src/vm/GlobalObject.cpp:238
#41 0x0000000000639803 in js::GlobalObject::ensureConstructor (key=JSProto_Object, global=..., cx=0x7ffff5f17000) at js/src/vm/GlobalObject.h:153
#42 js::GlobalObject::getOrCreateObjectPrototype (global=..., cx=0x7ffff5f17000) at js/src/vm/GlobalObject.h:301
#43 js::InitReflect (cx=<optimized out>, global=global@entry=...) at js/src/builtin/Reflect.cpp:210
#44 0x0000000000baba55 in js::GlobalObject::resolveConstructor (cx=<optimized out>, cx@entry=0x7ffff5f17000, global=global@entry=..., key=key@entry=JSProto_Reflect) at js/src/vm/GlobalObject.cpp:173
#45 0x00000000005b7109 in js::GlobalObject::ensureConstructor (cx=0x7ffff5f17000, global=..., key=JSProto_Reflect) at js/src/vm/GlobalObject.h:153
#46 0x00000000009fc9ea in JS_ResolveStandardClass (cx=0x7ffff5f17000, obj=..., id=..., resolved=0x7fffffffc48f) at js/src/jsapi.cpp:1063
#47 0x0000000000c2969a in js::CallResolveOp (recursedp=<synthetic pointer>, propp=..., id=..., obj=..., cx=<optimized out>) at js/src/vm/NativeObject-inl.h:801
#48 js::LookupOwnPropertyInline<(js::AllowGC)1> (cx=<optimized out>, obj=..., id=..., propp=..., donep=0x7fffffffc59f) at js/src/vm/NativeObject-inl.h:873
#49 0x0000000000c29d73 in NativeGetPropertyInline<(js::AllowGC)1> (cx=<optimized out>, cx@entry=0x7ffff5f17000, obj=..., receiver=..., id=..., nameLookup=nameLookup@entry=NotNameLookup, vp=...) at js/src/vm/NativeObject.cpp:2375
#50 0x0000000000c2a6c0 in js::NativeGetProperty (cx=cx@entry=0x7ffff5f17000, obj=..., obj@entry=..., receiver=..., id=..., vp=..., vp@entry=...) at js/src/vm/NativeObject.cpp:2423
#51 0x00000000004ed45d in js::GetProperty (vp=..., id=..., receiver=..., obj=..., cx=0x7ffff5f17000) at js/src/vm/NativeObject.h:1718
#52 js::GetProperty (vp=..., name=<optimized out>, receiver=..., obj=..., cx=0x7ffff5f17000) at js/src/vm/JSObject.h:787
#53 js::GetProperty (cx=0x7ffff5f17000, obj=..., receiver=..., name=<optimized out>, vp=...) at js/src/vm/JSObject.h:803
#54 0x000000000060e0d2 in JS_InitReflectParse (cx=<optimized out>, global=..., global@entry=...) at js/src/builtin/ReflectParse.cpp:3529
#55 0x0000000000471399 in NewGlobalObject (cx=<optimized out>, options=..., principals=principals@entry=0x0) at js/src/shell/js.cpp:8551
#56 0x000000000047190c in NewGlobal (cx=<optimized out>, argc=<optimized out>, vp=0x7ffff494b098) at js/src/shell/js.cpp:5321
#57 0x00000000005bd9f3 in CallJSNative (cx=0x7ffff5f17000, native=0x471840 <NewGlobal(JSContext*, unsigned int, JS::Value*)>, args=...) at js/src/vm/Interpreter.cpp:445
[...]
#71 main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at js/src/shell/js.cpp:9623
rax	0xbad0bad1f4d87420	-4985279376580381664
rbx	0x7ffff4dbe050	140737301438544
rcx	0x20b2ca0	34286752
rdx	0x7ffff4d86820	140737301211168
rsi	0x9	9
rdi	0x7ffff4dc3080	140737301459072
rbp	0x7fffffffaca0	140737488333984
rsp	0x7fffffffac98	140737488333976
r8	0x0	0
r9	0x4000001	67108865
r10	0x1	1
r11	0x246	582
r12	0x0	0
r13	0x7fffffffacf0	140737488334064
r14	0x7ffff4dc5920	140737301469472
r15	0x7fffffffae60	140737488334432
rip	0x4c19ec <js::NativeObject::hasAllFlags(js::BaseShape::Flag) const+12>
=> 0x4c19ec <js::NativeObject::hasAllFlags(js::BaseShape::Flag) const+12>:	mov    0x8(%rax),%eax
   0x4c19ef <js::NativeObject::hasAllFlags(js::BaseShape::Flag) const+15>:	shr    $0x4,%eax


Marking s-s based on crash address and GC.
Summary: Crash [@ js::NativeObject::hasAllFlags] with TypedObject → Crash [@ js::NativeObject::hasAllFlags] or Assertion failure: getElementsHeader()->initializedLength == getElementsHeader()->capacity, at /vm/NativeObject.h:545 with TypedObject
This is a problem in compacting GC to do with typed object type descriptor objects.  We already update these in a separate phase before any typed objects are updated, because tracing the latter involves interrogating the former about their layout.

Unfortunately this information is not just stored in these objects themselves but also in their children - e.g. some of their slots contain JS array objects.

So when we update these typed object type descriptors we also need to make sure we update any of their object children.
Assignee: nobody → jcoppeard
Attachment #8998831 - Flags: review?(sphink)
Comment on attachment 8998831 [details] [diff] [review]
bug1481093-update-type-descr-children

Review of attachment 8998831 [details] [diff] [review]:
-----------------------------------------------------------------

Nice fuzz bug.
Attachment #8998831 - Flags: review?(sphink) → review+
Comment on attachment 8998831 [details] [diff] [review]
bug1481093-update-type-descr-children

[Security approval request comment]
How easily could an exploit be constructed based on the patch? Very difficult.

Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem? No.

Which older supported branches are affected by this flaw? Not sure, let's say everything back to 48 to be sure.

If not all supported branches, which bug introduced the flaw? Worst case bug 1266107, although it's possible that was correct and subsequent changes to the typed object code have caused this.

Do you have backports for the affected branches? If not, how different, hard to create, and risky will they be? Should be trivial.

How likely is this patch to cause regressions; how much testing does it need? Unlikley.
Attachment #8998831 - Flags: sec-approval?
Blocks: 1266107
JSBugMon: The testcase found in this bug no longer reproduces (tried revision f650c0df72f9).
JSBugMon: Bisection requested, result:
autoBisect shows this is probably related to the following changeset:

The first bad revision is:
changeset:   https://hg.mozilla.org/mozilla-central/rev/c543368b25a6
user:        André Bargull
date:        Thu Aug 02 13:03:04 2018 -0700
summary:     Bug 1478503: Shrink capacity when modifying length on a non-extensible array. r=jandem

This iteration took 282.955 seconds to run.
Whiteboard: [jsbugmon:update,bisect] → [jsbugmon:update,ignore]
Calling this a sec-high.
Sec-approval+ for trunk. I'd like ESR60 and Beta patches made and nominated.
Attachment #8998831 - Flags: sec-approval? → sec-approval+
https://hg.mozilla.org/mozilla-central/rev/ec59471499f1
Group: javascript-core-security → core-security-release
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla63
Status: RESOLVED → VERIFIED
JSBugMon: This bug has been automatically verified fixed.
Please request Beta and ESR60 approval on this when you get a chance. It grafts cleanly to both as-landed.
Flags: needinfo?(jcoppeard)
Flags: in-testsuite+
Comment on attachment 8998831 [details] [diff] [review]
bug1481093-update-type-descr-children

Approval Request Comment
[Feature/Bug causing the regression]: Worst case, bug 1266107.
[User impact if declined]: Possible crash.
[Is this code covered by automated tests?]: Yes.
[Has the fix been verified in Nightly?]: Yes.
[Needs manual test from QE? If yes, steps to reproduce]: No.
[List of other uplifts needed for the feature/fix]: None.
[Is the change risky?]: No.
[Why is the change risky/not risky?]: This is a small and simple fix. 
[String changes made/needed]: None.
Flags: needinfo?(jcoppeard)
Attachment #8998831 - Flags: approval-mozilla-release?
Comment on attachment 8998831 [details] [diff] [review]
bug1481093-update-type-descr-children

[Approval Request Comment]
If this is not a sec:{high,crit} bug, please state case for ESR consideration: sec-high bug.
User impact if declined: Possible crash.
Fix Landed on Version: 63.
Risk to taking this patch (and alternatives if risky): Low.
String or UUID changes made by this patch: None.
Attachment #8998831 - Flags: approval-mozilla-esr60?
Comment on attachment 8998831 [details] [diff] [review]
bug1481093-update-type-descr-children

Fixes a sec issue and possible crash. Approved for 62.0b18 and ESR 60.2.
Attachment #8998831 - Flags: approval-mozilla-release?
Attachment #8998831 - Flags: approval-mozilla-esr60?
Attachment #8998831 - Flags: approval-mozilla-esr60+
Attachment #8998831 - Flags: approval-mozilla-beta+
Whiteboard: [jsbugmon:update,ignore] → [jsbugmon:update,ignore][adv-main62+][adv-esr60.2+]
Group: core-security-release
Keywords: bugmon
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: