Skip to content

Commit 9b270c5

Browse files
Meghana Guptaleirocks
authored andcommitted
[CVE-2018-8229] Edge - Chakra JIT Type confusion with hoisted SetConcatStrMultiItemBE instructions - Google, Inc.
1 parent 8af7189 commit 9b270c5

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

lib/Backend/GlobOpt.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16452,14 +16452,16 @@ void
1645216452
GlobOpt::OptHoistUpdateValueType(
1645316453
Loop* loop,
1645416454
IR::Instr* instr,
16455-
IR::Opnd* srcOpnd,
16455+
IR::Opnd** srcOpndPtr /* All code paths that change src, should update srcOpndPtr*/,
1645616456
Value* opndVal)
1645716457
{
16458-
if (opndVal == nullptr || instr->m_opcode == Js::OpCode::FromVar)
16458+
if (opndVal == nullptr || instr->m_opcode == Js::OpCode::FromVar || srcOpndPtr == nullptr || *srcOpndPtr == nullptr)
1645916459
{
1646016460
return;
1646116461
}
1646216462

16463+
IR::Opnd* srcOpnd = *srcOpndPtr;
16464+
1646316465
Sym* opndSym = srcOpnd->GetSym();;
1646416466

1646516467
if (opndSym)
@@ -16472,8 +16474,11 @@ GlobOpt::OptHoistUpdateValueType(
1647216474

1647316475
if (srcOpnd->GetValueType() != opndValueTypeInLandingPad)
1647416476
{
16477+
srcOpnd->SetValueType(opndValueTypeInLandingPad);
16478+
1647516479
if (instr->m_opcode == Js::OpCode::SetConcatStrMultiItemBE)
1647616480
{
16481+
Assert(!opndSym->IsPropertySym());
1647716482
Assert(!opndValueTypeInLandingPad.IsString());
1647816483
Assert(instr->GetDst());
1647916484

@@ -16484,6 +16489,9 @@ GlobOpt::OptHoistUpdateValueType(
1648416489
IR::Instr::New(Js::OpCode::Conv_PrimStr, strOpnd, srcOpnd->Use(instr->m_func), instr->m_func);
1648516490
instr->ReplaceSrc(srcOpnd, strOpnd);
1648616491

16492+
// Replace above will free srcOpnd, so reassign it
16493+
*srcOpndPtr = srcOpnd = reinterpret_cast<IR::Opnd *>(strOpnd);
16494+
1648716495
if (loop->bailOutInfo->bailOutInstr)
1648816496
{
1648916497
loop->bailOutInfo->bailOutInstr->InsertBefore(convPrimStrInstr);
@@ -16492,9 +16500,10 @@ GlobOpt::OptHoistUpdateValueType(
1649216500
{
1649316501
landingPad->InsertAfter(convPrimStrInstr);
1649416502
}
16495-
}
1649616503

16497-
srcOpnd->SetValueType(opndValueTypeInLandingPad);
16504+
// If we came here opndSym can't be PropertySym
16505+
return;
16506+
}
1649816507
}
1649916508

1650016509

@@ -16528,7 +16537,7 @@ GlobOpt::OptHoistInvariant(
1652816537
if (src1)
1652916538
{
1653016539
// We are hoisting this instruction possibly past other uses, which might invalidate the last use info. Clear it.
16531-
OptHoistUpdateValueType(loop, instr, src1, src1Val);
16540+
OptHoistUpdateValueType(loop, instr, &src1, src1Val);
1653216541

1653316542
if (src1->IsRegOpnd())
1653416543
{
@@ -16538,7 +16547,7 @@ GlobOpt::OptHoistInvariant(
1653816547
IR::Opnd* src2 = instr->GetSrc2();
1653916548
if (src2)
1654016549
{
16541-
OptHoistUpdateValueType(loop, instr, src2, src2Val);
16550+
OptHoistUpdateValueType(loop, instr, &src2, src2Val);
1654216551

1654316552
if (src2->IsRegOpnd())
1654416553
{

lib/Backend/GlobOpt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ class GlobOpt
758758
bool TryHoistInvariant(IR::Instr *instr, BasicBlock *block, Value *dstVal, Value *src1Val, Value *src2Val, bool isNotTypeSpecConv,
759759
const bool lossy = false, const bool forceInvariantHoisting = false, IR::BailOutKind bailoutKind = IR::BailOutInvalid);
760760
void HoistInvariantValueInfo(ValueInfo *const invariantValueInfoToHoist, Value *const valueToUpdate, BasicBlock *const targetBlock);
761-
void OptHoistUpdateValueType(Loop* loop, IR::Instr* instr, IR::Opnd* srcOpnd, Value *const srcVal);
761+
void OptHoistUpdateValueType(Loop* loop, IR::Instr* instr, IR::Opnd** srcOpndPtr, Value *const srcVal);
762762
public:
763763
static bool IsTypeSpecPhaseOff(Func const * func);
764764
static bool DoAggressiveIntTypeSpec(Func const * func);

0 commit comments

Comments
 (0)