Skip to content

Commit 8264b9b

Browse files
wyrichteakroshg
authored andcommitted
CVE-2018-8624 Edge - Chakra JIT Overflow
1 parent 8d21cde commit 8264b9b

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

lib/Backend/BackwardPass.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8669,7 +8669,15 @@ BackwardPass::RestoreInductionVariableValuesAfterMemOp(Loop *loop)
86698669

86708670
IR::Opnd *inductionVariableOpnd = IR::RegOpnd::New(sym, IRType::TyInt32, localFunc);
86718671
IR::Opnd *sizeOpnd = globOpt->GenerateInductionVariableChangeForMemOp(loop, inductionVariableChangeInfo.unroll);
8672-
loop->landingPad->InsertAfter(IR::Instr::New(opCode, inductionVariableOpnd, inductionVariableOpnd, sizeOpnd, loop->GetFunc()));
8672+
IR::Instr* restoreInductionVarInstr = IR::Instr::New(opCode, inductionVariableOpnd, inductionVariableOpnd, sizeOpnd, loop->GetFunc());
8673+
8674+
// The IR that restores the induction variable's value is placed before the MemOp. Since this IR can
8675+
// bailout to the loop's landing pad, placing this IR before the MemOp avoids performing the MemOp,
8676+
// bailing out because of this IR, and then performing the effects of the loop again.
8677+
loop->landingPad->InsertInstrBefore(restoreInductionVarInstr, loop->memOpInfo->instr);
8678+
8679+
// If restoring an induction variable results in an overflow, bailout to the loop's landing pad.
8680+
restoreInductionVarInstr->ConvertToBailOutInstr(loop->bailOutInfo, IR::BailOutOnOverflow);
86738681
};
86748682

86758683
for (auto it = loop->memOpInfo->inductionVariableChangeInfoMap->GetIterator(); it.IsValid(); it.MoveNext())

lib/Backend/FlowGraph.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ class Loop
694694
// Temporary map to reuse existing startIndexOpnd while emitting
695695
// 0 = !increment & !alreadyChanged, 1 = !increment & alreadyChanged, 2 = increment & !alreadyChanged, 3 = increment & alreadyChanged
696696
IR::RegOpnd* startIndexOpndCache[4];
697+
IR::Instr* instr;
697698
} MemOpInfo;
698699

699700
bool doMemOp : 1;

lib/Backend/GlobOpt.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16854,6 +16854,9 @@ GlobOpt::EmitMemop(Loop * loop, LoopCount *loopCount, const MemOpEmitData* emitD
1685416854
memopInstr->SetSrc2(sizeOpnd);
1685516855
insertBeforeInstr->InsertBefore(memopInstr);
1685616856

16857+
16858+
loop->memOpInfo->instr = memopInstr;
16859+
1685716860
#if DBG_DUMP
1685816861
if (DO_MEMOP_TRACE())
1685916862
{

0 commit comments

Comments
 (0)