Skip to content

Commit ee92757

Browse files
lucylqGithub Executorch
andauthored
Add bounds validation for FreeCall value_index in Method (pytorch#18176)
The FreeCall instruction handler directly indexes into values_ without bounds checking, enabling OOB memory access via malicious PTE files. This contrasts with JumpFalseCall which validates its index at init time, and MoveCall which uses bounds-checked accessors at execution time. Add init-time validation for FreeCall matching the JumpFalseCall pattern, and switch execution-time access to use the bounds-checked mutable_value() accessor for defense in depth. This PR was authored with the assistance of Claude. Co-authored-by: Github Executorch <github_executorch@arm.com>
1 parent 6bd9bca commit ee92757

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

runtime/executor/method.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,18 @@ Error Method::init(
10601060
n_value_);
10611061
chain_instruction_arg_lists[instr_idx] = InstructionArgs();
10621062
} break;
1063+
case executorch_flatbuffer::InstructionArguments::FreeCall: {
1064+
auto index =
1065+
static_cast<const executorch_flatbuffer::FreeCall*>(instr_args)
1066+
->value_index();
1067+
ET_CHECK_OR_RETURN_ERROR(
1068+
index >= 0 && static_cast<size_t>(index) < n_value_,
1069+
InvalidProgram,
1070+
"Index %zd negative or >= %" ET_PRIsize_t,
1071+
static_cast<ssize_t>(index),
1072+
n_value_);
1073+
chain_instruction_arg_lists[instr_idx] = InstructionArgs();
1074+
} break;
10631075
default: {
10641076
chain_instruction_arg_lists[instr_idx] = InstructionArgs();
10651077
} break;
@@ -1501,7 +1513,7 @@ Error Method::execute_instruction() {
15011513
// We know that instr_args_as_FreeCall is non-null because it was checked
15021514
// at init time.
15031515
auto free_call = instruction->instr_args_as_FreeCall();
1504-
auto t = values_[free_call->value_index()].toTensor();
1516+
auto t = mutable_value(free_call->value_index()).toTensor();
15051517
internal::reset_data_ptr(t);
15061518
} break;
15071519
default:

0 commit comments

Comments
 (0)