Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 74 additions & 22 deletions src/coreclr/jit/fgbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2081,23 +2081,26 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed

if (isInlining)
{
if (varNum < impInlineInfo->argCnt)
if (varNum >= impInlineInfo->argCnt)
{
impInlineInfo->inlArgInfo[varNum].argHasStargOp = true;
compInlineResult->NoteFatal(InlineObservation::CALLEE_BAD_ARGUMENT_NUMBER);
return;
}

impInlineInfo->inlArgInfo[varNum].argHasStargOp = true;
}
else
{
if (varNum >= info.compILargsCount)
{
BADCODE("bad argument number");
}

// account for possible hidden param
varNum = compMapILargNum(varNum);

// This check is only intended to prevent an AV. Bad varNum values will later
// be handled properly by the verifier.
if (varNum < lvaTableCnt)
{
// In non-inline cases, note written-to arguments.
lvaTable[varNum].lvHasILStoreOp = 1;
}
// In non-inline cases, note written-to arguments.
lvaTable[varNum].lvHasILStoreOp = 1;
}
}
break;
Expand All @@ -2124,6 +2127,12 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed
STLOC:
if (isInlining)
{
if (varNum >= info.compMethodInfo->locals.numArgs)
{
compInlineResult->NoteFatal(InlineObservation::CALLEE_BAD_LOCAL_NUMBER);
return;
}

InlLclVarInfo& lclInfo = impInlineInfo->lclVarInfo[varNum + impInlineInfo->argCnt];

if (lclInfo.lclHasStlocOp)
Expand All @@ -2137,21 +2146,21 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed
}
else
{
if (varNum >= info.compMethodInfo->locals.numArgs)
{
BADCODE("bad local number");
}

varNum += info.compArgsCount;

// This check is only intended to prevent an AV. Bad varNum values will later
// be handled properly by the verifier.
if (varNum < lvaTableCnt)
// In non-inline cases, note written-to locals.
if (lvaTable[varNum].lvHasILStoreOp)
{
// In non-inline cases, note written-to locals.
if (lvaTable[varNum].lvHasILStoreOp)
{
lvaTable[varNum].lvHasMultipleILStoreOp = 1;
}
else
{
lvaTable[varNum].lvHasILStoreOp = 1;
}
lvaTable[varNum].lvHasMultipleILStoreOp = 1;
}
else
{
lvaTable[varNum].lvHasILStoreOp = 1;
}
}
}
Expand Down Expand Up @@ -2189,6 +2198,12 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed
{
if (opcode == CEE_LDLOCA || opcode == CEE_LDLOCA_S)
{
if (varNum >= info.compMethodInfo->locals.numArgs)
{
compInlineResult->NoteFatal(InlineObservation::CALLEE_BAD_LOCAL_NUMBER);
return;
}

varType = impInlineInfo->lclVarInfo[varNum + impInlineInfo->argCnt].lclTypeInfo;

impInlineInfo->lclVarInfo[varNum + impInlineInfo->argCnt].lclHasLdlocaOp = true;
Expand All @@ -2197,6 +2212,12 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed
{
noway_assert(opcode == CEE_LDARGA || opcode == CEE_LDARGA_S);

if (varNum >= impInlineInfo->argCnt)
{
compInlineResult->NoteFatal(InlineObservation::CALLEE_BAD_ARGUMENT_NUMBER);
return;
}

varType = impInlineInfo->lclVarInfo[varNum].lclTypeInfo;

impInlineInfo->inlArgInfo[varNum].argHasLdargaOp = true;
Expand Down Expand Up @@ -2330,7 +2351,14 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed
case CEE_LDARG_3:
if (makeInlineObservations)
{
pushedStack.PushArgument(opcode - CEE_LDARG_0);
unsigned argNum = opcode - CEE_LDARG_0;
if (isInlining && (argNum >= impInlineInfo->argCnt))
{
compInlineResult->NoteFatal(InlineObservation::CALLEE_BAD_ARGUMENT_NUMBER);
return;
}

pushedStack.PushArgument(argNum);
handled = true;
}
break;
Expand All @@ -2347,6 +2375,12 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed

if (makeInlineObservations)
{
if (isInlining && (varNum >= impInlineInfo->argCnt))
{
compInlineResult->NoteFatal(InlineObservation::CALLEE_BAD_ARGUMENT_NUMBER);
return;
}

pushedStack.PushArgument(varNum);
handled = true;
}
Expand Down Expand Up @@ -2610,6 +2644,12 @@ void Compiler::fgObserveInlineConstants(OPCODE opcode, const FgStack& stack, boo
// Check for the double whammy of an incoming constant argument
// feeding a constant test.
unsigned varNum = FgStack::SlotTypeToArgNum(slot0);
if (varNum >= impInlineInfo->argCnt)
{
compInlineResult->NoteFatal(InlineObservation::CALLEE_BAD_ARGUMENT_NUMBER);
return;
}

if (impInlineInfo->inlArgInfo[varNum].argIsInvariant)
{
compInlineResult->Note(InlineObservation::CALLSITE_CONSTANT_ARG_FEEDS_TEST);
Expand Down Expand Up @@ -2652,6 +2692,12 @@ void Compiler::fgObserveInlineConstants(OPCODE opcode, const FgStack& stack, boo
compInlineResult->Note(InlineObservation::CALLEE_ARG_FEEDS_TEST);

unsigned varNum = FgStack::SlotTypeToArgNum(slot0);
if (varNum >= impInlineInfo->argCnt)
{
compInlineResult->NoteFatal(InlineObservation::CALLEE_BAD_ARGUMENT_NUMBER);
return;
}

if (impInlineInfo->inlArgInfo[varNum].argIsInvariant)
{
compInlineResult->Note(InlineObservation::CALLSITE_CONSTANT_ARG_FEEDS_TEST);
Expand All @@ -2663,6 +2709,12 @@ void Compiler::fgObserveInlineConstants(OPCODE opcode, const FgStack& stack, boo
compInlineResult->Note(InlineObservation::CALLEE_ARG_FEEDS_TEST);

unsigned varNum = FgStack::SlotTypeToArgNum(slot1);
if (varNum >= impInlineInfo->argCnt)
{
compInlineResult->NoteFatal(InlineObservation::CALLEE_BAD_ARGUMENT_NUMBER);
return;
}

if (impInlineInfo->inlArgInfo[varNum].argIsInvariant)
{
compInlineResult->Note(InlineObservation::CALLSITE_CONSTANT_ARG_FEEDS_TEST);
Expand Down
45 changes: 38 additions & 7 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6926,13 +6926,24 @@ void Compiler::impImportBlockCode(BasicBlock* block)

if (compIsForInlining())
{
if (lclNum >= impInlineInfo->argCnt)
{
compInlineResult->NoteFatal(InlineObservation::CALLEE_BAD_ARGUMENT_NUMBER);
return;
}

op1 = impInlineFetchArg(impInlineInfo->inlArgInfo[lclNum], impInlineInfo->lclVarInfo[lclNum]);
noway_assert(op1->OperIs(GT_LCL_VAR));
lclNum = op1->AsLclVar()->GetLclNum();

goto VAR_ST_VALID;
}

if (lclNum >= info.compILargsCount)
{
BADCODE("Bad IL");
}

lclNum = compMapILargNum(lclNum); // account for possible hidden param
assertImp(lclNum < numArgs);

Expand Down Expand Up @@ -6969,6 +6980,12 @@ void Compiler::impImportBlockCode(BasicBlock* block)
LOC_ST:
if (compIsForInlining())
{
if (lclNum >= info.compMethodInfo->locals.numArgs)
{
compInlineResult->NoteFatal(InlineObservation::CALLEE_BAD_LOCAL_NUMBER);
return;
}

lclTyp = impInlineInfo->lclVarInfo[lclNum + impInlineInfo->argCnt].lclTypeInfo;

/* Have we allocated a temp for this local? */
Expand Down Expand Up @@ -7140,6 +7157,12 @@ void Compiler::impImportBlockCode(BasicBlock* block)

if (compIsForInlining())
{
if (lclNum >= info.compMethodInfo->locals.numArgs)
{
compInlineResult->NoteFatal(InlineObservation::CALLEE_BAD_LOCAL_NUMBER);
return;
}

// Get the local type
lclTyp = impInlineInfo->lclVarInfo[lclNum + impInlineInfo->argCnt].lclTypeInfo;

Expand All @@ -7165,13 +7188,14 @@ void Compiler::impImportBlockCode(BasicBlock* block)
LDARGA:
JITDUMP(" %u", lclNum);

if (lclNum >= info.compILargsCount)
{
BADCODE("Bad IL");
}

if (compIsForInlining())
{
if (lclNum >= impInlineInfo->argCnt)
{
compInlineResult->NoteFatal(InlineObservation::CALLEE_BAD_ARGUMENT_NUMBER);
return;
}

// In IL, LDARGA(_S) is used to load the byref managed pointer of struct argument,
// followed by a ldfld to load the field.

Expand All @@ -7186,6 +7210,11 @@ void Compiler::impImportBlockCode(BasicBlock* block)
goto _PUSH_ADRVAR;
}

if (lclNum >= info.compILargsCount)
{
BADCODE("Bad IL");
}

lclNum = compMapILargNum(lclNum); // account for possible hidden param
assertImp(lclNum < numArgs);

Expand Down Expand Up @@ -11531,7 +11560,7 @@ void Compiler::impLoadArg(unsigned ilArgNum, IL_OFFSET offset)
{
if (compIsForInlining())
{
if (ilArgNum >= info.compArgsCount)
if (ilArgNum >= impInlineInfo->argCnt)
{
compInlineResult->NoteFatal(InlineObservation::CALLEE_BAD_ARGUMENT_NUMBER);
return;
Expand All @@ -11553,7 +11582,7 @@ void Compiler::impLoadArg(unsigned ilArgNum, IL_OFFSET offset)
}
else
{
if (ilArgNum >= info.compArgsCount)
if (ilArgNum >= info.compILargsCount)
{
BADCODE("Bad IL");
}
Expand Down Expand Up @@ -14571,6 +14600,8 @@ void Compiler::impInlineInitVars(InlineInfo* pInlineInfo)
unsigned Compiler::impInlineFetchLocal(unsigned lclNum DEBUGARG(const char* reason))
{
assert(compIsForInlining());
assert(lclNum < info.compMethodInfo->locals.numArgs);
assert(lclNum < MAX_INL_LCLS);

unsigned tmpNum = impInlineInfo->lclTmpNum[lclNum];

Expand Down
Loading
Loading