Skip to content

Commit

Permalink
[CVE-2018-0758] Integer overflow bug in the latest version of Edge ca…
Browse files Browse the repository at this point in the history
…using RCE - Individual
  • Loading branch information
meg-gupta authored and Thomas Moore (CHAKRA) committed Jan 5, 2018
1 parent a1c8240 commit 4db0bd2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 33 additions & 2 deletions lib/Backend/Lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8330,7 +8330,7 @@ Lowerer::LowerAddLeftDeadForString(IR::Instr *instr)
InsertCompareBranch(
regLeftCharLengthOpnd,
IR::IntConstOpnd::New(Js::JavascriptString::MaxCharLength, TyUint32, m_func),
Js::OpCode::BrGt_A,
Js::OpCode::BrGe_A,
labelHelper,
insertBeforeInstr);

Expand Down Expand Up @@ -14702,6 +14702,29 @@ IR::BranchInstr *Lowerer::InsertTestBranch(
return InsertBranch(branchOpCode, isUnsigned, target, insertBeforeInstr);
}

/* Inserts add with an overflow check, if we overflow throw OOM
* add dst, src
* jno $continueLabel
* overflow code
* $continueLabel : fall through
*/
void Lowerer::InsertAddWithOverflowCheck(
const bool needFlags,
IR::Opnd *const dst,
IR::Opnd *src1,
IR::Opnd *src2,
IR::Instr *const insertBeforeInstr,
IR::Instr **const onOverflowInsertBeforeInstrRef)
{
Func * func = insertBeforeInstr->m_func;
InsertAdd(needFlags, dst, src1, src2, insertBeforeInstr);

IR::LabelInstr *const continueLabel = IR::LabelInstr::New(Js::OpCode::Label, func, false);
InsertBranch(LowererMD::MDNotOverflowBranchOpcode, continueLabel, insertBeforeInstr);

*onOverflowInsertBeforeInstrRef = continueLabel;
}

IR::Instr *Lowerer::InsertAdd(
const bool needFlags,
IR::Opnd *const dst,
Expand Down Expand Up @@ -23210,7 +23233,15 @@ Lowerer::LowerSetConcatStrMultiItem(IR::Instr * instr)
srcLength = IR::RegOpnd::New(TyUint32, func);
InsertMove(srcLength, IR::IndirOpnd::New(srcOpnd, Js::ConcatStringMulti::GetOffsetOfcharLength(), TyUint32, func), instr);
}
InsertAdd(false, dstLength, dstLength, srcLength, instr);

IR::Instr *onOverflowInsertBeforeInstr;
InsertAddWithOverflowCheck(false, dstLength, dstLength, srcLength, instr, &onOverflowInsertBeforeInstr);
IR::Instr* callInstr = IR::Instr::New(Js::OpCode::Call, func);
callInstr->SetSrc1(IR::HelperCallOpnd::New(IR::HelperOp_OutOfMemoryError, func));

instr->InsertBefore(onOverflowInsertBeforeInstr);
onOverflowInsertBeforeInstr->InsertBefore(callInstr);
this->m_lowererMD.LowerCall(callInstr, 0);

dstOpnd->SetOffset(dstOpnd->GetOffset() * sizeof(Js::JavascriptString *) + Js::ConcatStringMulti::GetOffsetOfSlots());

Expand Down
2 changes: 2 additions & 0 deletions lib/Backend/Lower.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ class Lowerer

public:
static void InsertDecUInt32PreventOverflow(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr, IR::Instr * *const onOverflowInsertBeforeInstrRef = nullptr);
static void InsertAddWithOverflowCheck(const bool needFlags, IR::Opnd *const dst, IR::Opnd *src1, IR::Opnd *src2, IR::Instr *const insertBeforeInstr, IR::Instr **const onOverflowInsertBeforeInstrRef);

void InsertFloatCheckForZeroOrNanBranch(IR::Opnd *const src, const bool branchOnZeroOrNan, IR::LabelInstr *const target, IR::LabelInstr *const fallthroughLabel, IR::Instr *const insertBeforeInstr);

public:
Expand Down

0 comments on commit 4db0bd2

Please sign in to comment.