Skip to content

Commit c7999d9

Browse files
atulkattiakroshg
authored andcommitted
[CVE-2020-0713] Chakra - incorrect offset for homeObj on cross-site objects.
1 parent d898026 commit c7999d9

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

lib/Backend/Lower.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25014,9 +25014,9 @@ Lowerer::GenerateLdHomeObj(IR::Instr* instr)
2501425014
Func *func = instr->m_func;
2501525015

2501625016
IR::LabelInstr *labelDone = IR::LabelInstr::New(Js::OpCode::Label, func, false);
25017-
IR::LabelInstr *labelInlineFunc = IR::LabelInstr::New(Js::OpCode::Label, func, false);
2501825017
IR::LabelInstr *testLabel = IR::LabelInstr::New(Js::OpCode::Label, func, false);
2501925018
IR::LabelInstr *scriptFuncLabel = IR::LabelInstr::New(Js::OpCode::Label, func, false);
25019+
LABELNAMESET(scriptFuncLabel, "ScriptFunctionWithHomeObj");
2502025020
IR::Opnd *opndUndefAddress = this->LoadLibraryValueOpnd(instr, LibraryValue::ValueUndefined);
2502125021

2502225022
IR::RegOpnd *instanceRegOpnd = IR::RegOpnd::New(TyMachPtr, func);
@@ -25037,23 +25037,30 @@ Lowerer::GenerateLdHomeObj(IR::Instr* instr)
2503725037

2503825038
if (func->GetJITFunctionBody()->HasHomeObj())
2503925039
{
25040-
// Is this an function with inline cache and home obj??
25041-
IR::Opnd * vtableAddressInlineFuncHomObjOpnd = this->LoadVTableValueOpnd(instr, VTableValue::VtableScriptFunctionWithInlineCacheAndHomeObj);
25042-
IR::BranchInstr* inlineFuncHomObjOpndBr = InsertCompareBranch(IR::IndirOpnd::New(instanceRegOpnd, 0, TyMachPtr, func), vtableAddressInlineFuncHomObjOpnd, Js::OpCode::BrNeq_A, labelInlineFunc, instr);
25043-
InsertObjectPoison(instanceRegOpnd, inlineFuncHomObjOpndBr, instr, false);
25044-
IR::IndirOpnd *indirInlineFuncHomeObjOpnd = IR::IndirOpnd::New(instanceRegOpnd, Js::FunctionWithHomeObj<Js::ScriptFunctionWithInlineCache>::GetOffsetOfHomeObj(), TyMachPtr, func);
25045-
Lowerer::InsertMove(instanceRegOpnd, indirInlineFuncHomeObjOpnd, instr);
25046-
InsertBranch(Js::OpCode::Br, testLabel, instr);
25040+
IR::RegOpnd* funcObjHasInlineCachesOpnd = IR::RegOpnd::New(TyUint8, instr->m_func);
25041+
this->InsertMove(funcObjHasInlineCachesOpnd, IR::IndirOpnd::New(instanceRegOpnd, Js::ScriptFunction::GetOffsetOfHasInlineCaches(), TyUint8, instr->m_func), instr);
2504725042

25048-
instr->InsertBefore(labelInlineFunc);
25049-
25050-
// Is this a function with inline cache, home obj and computed name??
25051-
IR::Opnd * vtableAddressInlineFuncHomObjCompNameOpnd = this->LoadVTableValueOpnd(instr, VTableValue::VtableScriptFunctionWithInlineCacheHomeObjAndComputedName);
25052-
IR::BranchInstr* inlineFuncHomObjCompNameBr = InsertCompareBranch(IR::IndirOpnd::New(instanceRegOpnd, 0, TyMachPtr, func), vtableAddressInlineFuncHomObjCompNameOpnd, Js::OpCode::BrNeq_A, scriptFuncLabel, instr);
25043+
IR::BranchInstr* inlineFuncHomObjCompNameBr = InsertTestBranch(funcObjHasInlineCachesOpnd, funcObjHasInlineCachesOpnd, Js::OpCode::BrEq_A, scriptFuncLabel, instr);
2505325044
InsertObjectPoison(instanceRegOpnd, inlineFuncHomObjCompNameBr, instr, false);
25054-
IR::IndirOpnd *indirInlineFuncHomeObjCompNameOpnd = IR::IndirOpnd::New(instanceRegOpnd, Js::FunctionWithComputedName<Js::FunctionWithHomeObj<Js::ScriptFunctionWithInlineCache>>::GetOffsetOfHomeObj(), TyMachPtr, func);
25055-
Lowerer::InsertMove(instanceRegOpnd, indirInlineFuncHomeObjCompNameOpnd, instr);
25056-
InsertBranch(Js::OpCode::Br, testLabel, instr);
25045+
25046+
if (func->GetJITFunctionBody()->HasComputedName())
25047+
{
25048+
// Is this a function with inline cache, home obj and computed name?
25049+
{
25050+
IR::IndirOpnd* indirInlineFuncHomeObjCompNameOpnd = IR::IndirOpnd::New(instanceRegOpnd, Js::FunctionWithComputedName<Js::FunctionWithHomeObj<Js::ScriptFunctionWithInlineCache>>::GetOffsetOfHomeObj(), TyMachPtr, func);
25051+
Lowerer::InsertMove(instanceRegOpnd, indirInlineFuncHomeObjCompNameOpnd, instr);
25052+
InsertBranch(Js::OpCode::Br, testLabel, instr);
25053+
}
25054+
}
25055+
else
25056+
{
25057+
// Is this a function with inline cache and home obj?
25058+
{
25059+
IR::IndirOpnd* indirInlineFuncHomeObjOpnd = IR::IndirOpnd::New(instanceRegOpnd, Js::FunctionWithHomeObj<Js::ScriptFunctionWithInlineCache>::GetOffsetOfHomeObj(), TyMachPtr, func);
25060+
Lowerer::InsertMove(instanceRegOpnd, indirInlineFuncHomeObjOpnd, instr);
25061+
InsertBranch(Js::OpCode::Br, testLabel, instr);
25062+
}
25063+
}
2505725064

2505825065
instr->InsertBefore(scriptFuncLabel);
2505925066
IR::IndirOpnd *indirOpnd = IR::IndirOpnd::New(instanceRegOpnd, Js::ScriptFunctionWithHomeObj::GetOffsetOfHomeObj(), TyMachPtr, func);

0 commit comments

Comments
 (0)