Skip to content

Commit fa9a817

Browse files
dbortfacebook-github-bot
authored andcommitted
Check for out-of-range argument value indices (#1517)
Summary: Pull Request resolved: #1517 Ensure that arg indices are in range before looking up values. Corrupted files with very large indices could cause arbitrary memory reads. Reviewed By: lucylq Differential Revision: D52451739 fbshipit-source-id: 851d047eb217784e1e9f1f87282ed4808becfca8
1 parent 89958d2 commit fa9a817

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

runtime/executor/method.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,22 @@ namespace {
215215

216216
Result<InstructionArgs> gen_instruction_arguments(
217217
MemoryAllocator* method_allocator,
218+
size_t num_values,
218219
EValue* values,
219220
size_t num_args,
220221
const int32_t* arg_idxs) {
221222
EValue** arg_list =
222223
ET_ALLOCATE_LIST_OR_RETURN_ERROR(method_allocator, EValue*, num_args);
223224
for (size_t i = 0; i < num_args; ++i) {
224-
arg_list[i] = &values[arg_idxs[i]];
225+
int32_t arg_idx = arg_idxs[i];
226+
ET_LOG(Error, "Argument index %d vs num_values %zu", arg_idx, num_values);
227+
ET_CHECK_OR_RETURN_ERROR(
228+
arg_idx < num_values,
229+
InvalidProgram,
230+
"Arg index %d >= %zu",
231+
arg_idx,
232+
num_values);
233+
arg_list[i] = &values[arg_idx];
225234
}
226235
return InstructionArgs(arg_list, num_args);
227236
}
@@ -582,7 +591,11 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
582591
const auto arg_idxs =
583592
instruction->instr_args_as_KernelCall()->args();
584593
auto res = gen_instruction_arguments(
585-
method_allocator, values_, arg_idxs->size(), arg_idxs->data());
594+
method_allocator,
595+
n_value_,
596+
values_,
597+
arg_idxs->size(),
598+
arg_idxs->data());
586599
if (!res.ok()) {
587600
return res.error();
588601
}
@@ -603,7 +616,11 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
603616
const auto arg_idxs =
604617
instruction->instr_args_as_DelegateCall()->args();
605618
auto res = gen_instruction_arguments(
606-
method_allocator, values_, arg_idxs->size(), arg_idxs->data());
619+
method_allocator,
620+
n_value_,
621+
values_,
622+
arg_idxs->size(),
623+
arg_idxs->data());
607624
if (!res.ok()) {
608625
return res.error();
609626
}

0 commit comments

Comments
 (0)