Skip to content

Commit 362e965

Browse files
MikeHolmanatulkatti
authored andcommitted
[CVE-2019-1106] Chakra JIT Overflow
1 parent efab310 commit 362e965

File tree

7 files changed

+40
-7
lines changed

7 files changed

+40
-7
lines changed

lib/Backend/Func.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ Func::Codegen(JitArenaAllocator *alloc, JITTimeWorkItem * workItem,
345345
case RejitReason::TrackIntOverflowDisabled:
346346
outputData->disableTrackCompoundedIntOverflow = TRUE;
347347
break;
348+
case RejitReason::MemOpDisabled:
349+
outputData->disableMemOp = TRUE;
350+
break;
348351
default:
349352
Assume(UNREACHED);
350353
}
@@ -1124,6 +1127,12 @@ Func::IsTrackCompoundedIntOverflowDisabled() const
11241127
return (HasProfileInfo() && GetReadOnlyProfileInfo()->IsTrackCompoundedIntOverflowDisabled()) || m_output.IsTrackCompoundedIntOverflowDisabled();
11251128
}
11261129

1130+
bool
1131+
Func::IsMemOpDisabled() const
1132+
{
1133+
return (HasProfileInfo() && GetReadOnlyProfileInfo()->IsMemOpDisabled()) || m_output.IsMemOpDisabled();
1134+
}
1135+
11271136
bool
11281137
Func::IsArrayCheckHoistDisabled() const
11291138
{

lib/Backend/Func.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,7 @@ static const unsigned __int64 c_debugFillPattern8 = 0xcececececececece;
995995
void SetScopeObjSym(StackSym * sym);
996996
StackSym * GetScopeObjSym();
997997
bool IsTrackCompoundedIntOverflowDisabled() const;
998+
bool IsMemOpDisabled() const;
998999
bool IsArrayCheckHoistDisabled() const;
9991000
bool IsStackArgOptDisabled() const;
10001001
bool IsSwitchOptDisabled() const;

lib/Backend/GlobOpt.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,7 +2624,7 @@ GlobOpt::OptInstr(IR::Instr *&instr, bool* isInstrRemoved)
26242624
!(instr->IsJitProfilingInstr()) &&
26252625
this->currentBlock->loop && !IsLoopPrePass() &&
26262626
!func->IsJitInDebugMode() &&
2627-
(func->HasProfileInfo() && !func->GetReadOnlyProfileInfo()->IsMemOpDisabled()) &&
2627+
!func->IsMemOpDisabled() &&
26282628
this->currentBlock->loop->doMemOp)
26292629
{
26302630
CollectMemOpInfo(instrPrev, instr, src1Val, src2Val);
@@ -16686,7 +16686,14 @@ GlobOpt::GenerateInductionVariableChangeForMemOp(Loop *loop, byte unroll, IR::In
1668616686
}
1668716687
else
1668816688
{
16689-
uint size = (loopCount->LoopCountMinusOneConstantValue() + 1) * unroll;
16689+
int32 loopCountMinusOnePlusOne;
16690+
int32 size;
16691+
if (Int32Math::Add(loopCount->LoopCountMinusOneConstantValue(), 1, &loopCountMinusOnePlusOne) ||
16692+
Int32Math::Mul(loopCountMinusOnePlusOne, unroll, &size))
16693+
{
16694+
throw Js::RejitException(RejitReason::MemOpDisabled);
16695+
}
16696+
Assert(size > 0);
1669016697
sizeOpnd = IR::IntConstOpnd::New(size, IRType::TyUint32, localFunc);
1669116698
}
1669216699
loop->memOpInfo->inductionVariableOpndPerUnrollMap->Add(unroll, sizeOpnd);

lib/Backend/JITOutput.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ JITOutput::IsTrackCompoundedIntOverflowDisabled() const
6565
return m_outputData->disableTrackCompoundedIntOverflow != FALSE;
6666
}
6767

68+
bool
69+
JITOutput::IsMemOpDisabled() const
70+
{
71+
return m_outputData->disableMemOp != FALSE;
72+
}
73+
6874
bool
6975
JITOutput::IsArrayCheckHoistDisabled() const
7076
{

lib/Backend/JITOutput.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class JITOutput
2222
void RecordXData(BYTE * xdata);
2323
#endif
2424
bool IsTrackCompoundedIntOverflowDisabled() const;
25+
bool IsMemOpDisabled() const;
2526
bool IsArrayCheckHoistDisabled() const;
2627
bool IsStackArgOptDisabled() const;
2728
bool IsSwitchOptDisabled() const;

lib/Backend/NativeCodeGenerator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,10 @@ NativeCodeGenerator::CodeGen(PageAllocator * pageAllocator, CodeGenWorkItem* wor
12341234
{
12351235
body->GetAnyDynamicProfileInfo()->DisableTrackCompoundedIntOverflow();
12361236
}
1237+
if (jitWriteData.disableMemOp)
1238+
{
1239+
body->GetAnyDynamicProfileInfo()->DisableMemOp();
1240+
}
12371241
}
12381242

12391243
if (jitWriteData.disableInlineApply)

lib/JITIDL/JITTypes.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -838,37 +838,42 @@ typedef struct JITOutputIDL
838838
boolean disableStackArgOpt;
839839
boolean disableSwitchOpt;
840840
boolean disableTrackCompoundedIntOverflow;
841-
boolean isInPrereservedRegion;
841+
boolean disableMemOp;
842842

843+
boolean isInPrereservedRegion;
843844
boolean hasBailoutInstr;
844-
845845
boolean hasJittedStackClosure;
846+
IDL_PAD1(0)
846847

847848
unsigned short pdataCount;
848849
unsigned short xdataSize;
849850

850851
unsigned short argUsedForBranch;
852+
IDL_PAD2(1)
851853

852854
int localVarSlotsOffset; // FunctionEntryPointInfo only
855+
853856
int localVarChangedOffset; // FunctionEntryPointInfo only
854857
unsigned int frameHeight;
855858

856-
857859
unsigned int codeSize;
858860
unsigned int throwMapOffset;
861+
859862
unsigned int throwMapCount;
860863
unsigned int inlineeFrameOffsetArrayOffset;
861-
unsigned int inlineeFrameOffsetArrayCount;
862864

865+
unsigned int inlineeFrameOffsetArrayCount;
863866
unsigned int propertyGuardCount;
867+
864868
unsigned int ctorCachesCount;
869+
X64_PAD4(2)
865870

866871
#if TARGET_64
867872
CHAKRA_PTR xdataAddr;
868873
#elif defined(_M_ARM)
869874
unsigned int xdataOffset;
870875
#else
871-
X86_PAD4(0)
876+
X86_PAD4(3)
872877
#endif
873878
CHAKRA_PTR codeAddress;
874879
CHAKRA_PTR thunkAddress;

0 commit comments

Comments
 (0)