Skip to content

Commit edb8c98

Browse files
lucylqGithub Executorchclaude
authored
Validate XNNPACK tensor flags are valid (#19102)
1. Attacker sets that flag on an external tensor. 2. xnnpack thinks the tensor is owned by itself, and frees it inside the backend. 3. et runtime also frees it at method destruction. Test Plan: Build and run executor runner against problematic PTE file: ``` # Build executor runner: cmake -B cmake-out \ -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON \ -DEXECUTORCH_BUILD_XNNPACK=ON cmake --build cmake-out -j16 --target executor_runner # Output (executorch) [lfq@devvm11764.nha0 /data/users/lfq/security/executorch (f9f29e7)]$ ./cmake-out/executor_runner --model_path=/data/users/lfq/security/executorch_repros/TOB-EXECUTORCH-44.pte ``` Previous ``` (executorch) [lfq@devvm11764.nha0 /data/users/lfq/security/executorch (security44)]$ ./cmake-out/executor_runner --model_path=/data/users/lfq/security/executorch_repros/TOB-EXECUTORCH-44.pte Note (XNNPACK): l1_data_cache_bytes=32768, l1_data_cache_line_size=64, l1_data_cache_associativity=8, l1_data_cache_num_sets=64. (init_hardware_config, /data/users/lfq/security/executorch/backends/xnnpack/third-party/XNNPACK/src/configs/hardware-config.c:417) Note (XNNPACK): l2_data_cache_bytes=1048576, l2_data_cache_line_size=64, l2_data_cache_associativity=8, l2_data_cache_num_sets=2048. (init_hardware_config, /data/users/lfq/security/executorch/backends/xnnpack/third-party/XNNPACK/src/configs/hardware-config.c:436) I 00:00:00.002612 executorch:cpuinfo_utils.cpp:71] Reading file /sys/devices/soc0/image_version I 00:00:00.002640 executorch:cpuinfo_utils.cpp:87] Failed to open midr file /sys/devices/soc0/image_version I 00:00:00.002657 executorch:cpuinfo_utils.cpp:100] Reading file /sys/devices/system/cpu/cpu0/regs/identification/midr_el1 I 00:00:00.002664 executorch:cpuinfo_utils.cpp:109] Failed to open midr file /sys/devices/system/cpu/cpu0/regs/identification/midr_el1 I 00:00:00.002671 executorch:cpuinfo_utils.cpp:125] CPU info and manual query on # of cpus dont match. I 00:00:00.002672 executorch:executor_runner.cpp:223] Resetting threadpool with num threads = 0 I 00:00:00.002722 executorch:executor_runner.cpp:374] Model file /data/users/lfq/security/executorch_repros/TOB-EXECUTORCH-44.pte is loaded. I 00:00:00.002729 executorch:executor_runner.cpp:384] Using method forward I 00:00:00.002739 executorch:executor_runner.cpp:435] Setting up planned buffer 0, size 112. E 00:00:00.002806 executorch:XNNCompiler.cpp:331] Tensor value has unsupported flag bits 0xffffff00 E 00:00:00.002824 executorch:XNNPACKBackend.cpp:122] XNNCompiler::compileModel failed: 0x23 E 00:00:00.002827 executorch:method.cpp:127] Init failed for backend XnnpackBackend: 0x23 F 00:00:00.002830 executorch:executor_runner.cpp:459] In function main(), assert failed (method.ok()): Loading of method forward failed with status 0x23 Aborted (core dumped) ``` After, graceful error ``` (executorch) [lfq@devvm11764.nha0 /data/users/lfq/security/executorch (security44)]$ ./cmake-out/executor_runner --model_path=/data/users/lfq/security/executorch_repros/TOB-EXECUTORCH-44.pte Note (XNNPACK): l1_data_cache_bytes=32768, l1_data_cache_line_size=64, l1_data_cache_associativity=8, l1_data_cache_num_sets=64. (init_hardware_config, /data/users/lfq/security/executorch/backends/xnnpack/third-party/XNNPACK/src/configs/hardware-config.c:417) Note (XNNPACK): l2_data_cache_bytes=1048576, l2_data_cache_line_size=64, l2_data_cache_associativity=8, l2_data_cache_num_sets=2048. (init_hardware_config, /data/users/lfq/security/executorch/backends/xnnpack/third-party/XNNPACK/src/configs/hardware-config.c:436) I 00:00:00.002562 executorch:cpuinfo_utils.cpp:71] Reading file /sys/devices/soc0/image_version I 00:00:00.002595 executorch:cpuinfo_utils.cpp:87] Failed to open midr file /sys/devices/soc0/image_version I 00:00:00.002607 executorch:cpuinfo_utils.cpp:100] Reading file /sys/devices/system/cpu/cpu0/regs/identification/midr_el1 I 00:00:00.002618 executorch:cpuinfo_utils.cpp:109] Failed to open midr file /sys/devices/system/cpu/cpu0/regs/identification/midr_el1 I 00:00:00.002623 executorch:cpuinfo_utils.cpp:125] CPU info and manual query on # of cpus dont match. I 00:00:00.002628 executorch:executor_runner.cpp:223] Resetting threadpool with num threads = 0 I 00:00:00.002672 executorch:executor_runner.cpp:374] Model file /data/users/lfq/security/executorch_repros/TOB-EXECUTORCH-44.pte is loaded. I 00:00:00.002678 executorch:executor_runner.cpp:384] Using method forward I 00:00:00.002688 executorch:executor_runner.cpp:435] Setting up planned buffer 0, size 112. E 00:00:00.002750 executorch:XNNCompiler.cpp:331] Tensor value has unsupported flag bits 0xffffff00 E 00:00:00.002761 executorch:XNNPACKBackend.cpp:122] XNNCompiler::compileModel failed: 0x23 E 00:00:00.002769 executorch:method.cpp:127] Init failed for backend XnnpackBackend: 0x23 F 00:00:00.002772 executorch:executor_runner.cpp:459] In function main(), assert failed (method.ok()): Loading of method forward failed with status 0x23 ``` Co-authored-by: Github Executorch <github_executorch@arm.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4a69750 commit edb8c98

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

backends/xnnpack/runtime/XNNCompiler.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,15 @@ Error defineTensor(
319319
ET_CHECK_OR_RETURN_ERROR(
320320
tensor_value != nullptr, InvalidProgram, "Deserialized tensor is null");
321321

322+
// Validate that tensor_value->flags() is a subset of the allowed flags.
323+
constexpr uint32_t kAllowedFlagsMask =
324+
XNN_VALUE_FLAG_EXTERNAL_INPUT | XNN_VALUE_FLAG_EXTERNAL_OUTPUT;
325+
ET_CHECK_OR_RETURN_ERROR(
326+
(tensor_value->flags() & ~kAllowedFlagsMask) == 0,
327+
InvalidProgram,
328+
"Tensor value has unsupported flag bits 0x%x",
329+
tensor_value->flags());
330+
322331
// Get tensor dims, here we need to use a vector in order to properly
323332
// convert the uint32_t* to size_t*. Scalar tensors (rank 0) are permitted
324333
// to have a null dims vector; in that case dims_data is empty.

0 commit comments

Comments
 (0)