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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Reachable Assertion Abort in ExecuTorch create_tensor_layout() via Unvalidated ScalarType (.ptd)
|
| 2 |
+
|
| 3 |
+
**Target:** ExecuTorch 1.3.1 (.ptd, huntr Model File Vulnerability program)
|
| 4 |
+
**Severity:** Low-Medium (Denial of Service)
|
| 5 |
+
**CWE:** CWE-20 (Improper Input Validation)
|
| 6 |
+
**Component:** `extension/flat_tensor/flat_tensor_data_map.cpp` (call site) / `runtime/core/exec_aten/util/scalar_type_util.h` (abort site)
|
| 7 |
+
**Authentication Required:** No — only requires a victim application to load an attacker-supplied `.ptd` file and call a public API.
|
| 8 |
+
|
| 9 |
+
## Summary
|
| 10 |
+
|
| 11 |
+
`create_tensor_layout()` casts the raw `scalar_type` byte from a `.ptd`'s `TensorLayout` table directly to the `ScalarType` enum with no validation, then passes it into `TensorLayout::create()`, which eventually calls `elementSize()` to compute the tensor's byte size. `elementSize()`'s switch statement has no `default` case that returns an error — it calls `ET_CHECK_MSG(false, "Unknown ScalarType...")`, which **aborts the process**. An out-of-range `scalar_type` byte value in an otherwise well-formed `.ptd` file therefore causes a deliberate but attacker-reachable assertion abort.
|
| 12 |
+
|
| 13 |
+
Notably, the equivalent `.pte` code path (`tensor_parser_exec_aten.cpp`'s `parseTensor()`) **does** validate `scalar_type` with `isValid()` before use and returns a clean `InvalidProgram` error for exactly this case — proving this `.ptd` code path is missing a check that the parallel `.pte` code path already implements correctly.
|
| 14 |
+
|
| 15 |
+
**Confirmed against the pristine, unmodified ExecuTorch 1.3.1 source.**
|
| 16 |
+
|
| 17 |
+
## Vulnerability Details
|
| 18 |
+
|
| 19 |
+
`runtime/executor/tensor_parser_exec_aten.cpp` (the correct, existing pattern for `.pte` tensors):
|
| 20 |
+
|
| 21 |
+
```cpp
|
| 22 |
+
ScalarType scalar_type = static_cast<ScalarType>(s_tensor->scalar_type());
|
| 23 |
+
ET_CHECK_OR_RETURN_ERROR(
|
| 24 |
+
isValid(scalar_type),
|
| 25 |
+
InvalidProgram,
|
| 26 |
+
"Invalid or unsupported ScalarType %" PRId8,
|
| 27 |
+
static_cast<int8_t>(scalar_type));
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
`extension/flat_tensor/flat_tensor_data_map.cpp`'s `create_tensor_layout()` (the `.ptd` TensorLayout equivalent — pristine 1.3.1 source, lines 97–108) has no such check:
|
| 31 |
+
|
| 32 |
+
```cpp
|
| 33 |
+
Result<const TensorLayout> create_tensor_layout(
|
| 34 |
+
const flat_tensor_flatbuffer::TensorLayout* tensor_layout) {
|
| 35 |
+
ScalarType scalar_type =
|
| 36 |
+
static_cast<ScalarType>(tensor_layout->scalar_type()); // no isValid() check
|
| 37 |
+
const int dim = tensor_layout->sizes()->size();
|
| 38 |
+
...
|
| 39 |
+
return TensorLayout::create(
|
| 40 |
+
Span<const int32_t>(serialized_sizes, dim),
|
| 41 |
+
Span<const uint8_t>(serialized_dim_order, dim),
|
| 42 |
+
scalar_type);
|
| 43 |
+
}
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
`runtime/core/exec_aten/util/scalar_type_util.h`'s `elementSize()`:
|
| 47 |
+
|
| 48 |
+
```cpp
|
| 49 |
+
inline size_t elementSize(::executorch::aten::ScalarType t) {
|
| 50 |
+
#define CASE_ELEMENTSIZE_CASE(ctype, name) \
|
| 51 |
+
case ::executorch::aten::ScalarType::name: return sizeof(ctype);
|
| 52 |
+
|
| 53 |
+
switch (t) {
|
| 54 |
+
ET_FORALL_SCALAR_TYPES(CASE_ELEMENTSIZE_CASE)
|
| 55 |
+
default:
|
| 56 |
+
ET_CHECK_MSG(false, "Unknown ScalarType %" PRId8, static_cast<int8_t>(t)); // <-- aborts
|
| 57 |
+
}
|
| 58 |
+
#undef CASE_ELEMENTSIZE_CASE
|
| 59 |
+
}
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
`ET_CHECK_MSG(false, ...)` in this codebase calls `runtime_abort()` → `pal_abort()` → `et_pal_abort()`, terminating the process. This macro is designed for invariants the code asserts should never occur given prior validation — it is not designed to directly validate untrusted external input. Because `create_tensor_layout()` never validates `scalar_type` before it flows into this call chain, an attacker can trigger this "should never happen" path on demand.
|
| 63 |
+
|
| 64 |
+
## Steps to Reproduce
|
| 65 |
+
|
| 66 |
+
### Environment
|
| 67 |
+
Linux x86-64, ExecuTorch 1.3.1 pristine source, clang-16, CMake, Ninja. No authentication, no host access.
|
| 68 |
+
|
| 69 |
+
### 1. Build and harness
|
| 70 |
+
|
| 71 |
+
Identical to REPORT-01 (same build flags, same `poc/harness_flat_tensor_fuzzer.cpp`).
|
| 72 |
+
|
| 73 |
+
### 2. PoC file
|
| 74 |
+
|
| 75 |
+
`poc/poc_invalid_scalar_type.ptd` (272 bytes, **included in this report — sha256 `b5972dad3d9e5cf23434270c1dadc2a03dd51b3c4fde8661b38f1e8a1e9494fd`**) is a well-formed `.ptd` file with one `NamedData` entry (`key = "weight1"`) whose `tensor_layout` has valid `sizes`/`dim_order` but a `scalar_type` byte value outside the range defined by `ET_FORALL_SCALAR_TYPES`.
|
| 76 |
+
|
| 77 |
+
### 3. Trigger the crash
|
| 78 |
+
|
| 79 |
+
```bash
|
| 80 |
+
export ASAN_OPTIONS="abort_on_error=1:symbolize=0"
|
| 81 |
+
export UBSAN_OPTIONS="halt_on_error=1:print_stacktrace=0"
|
| 82 |
+
./poc_harness -timeout=5 -runs=0 poc/poc_invalid_scalar_type.ptd
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
### Expected result (secure behavior)
|
| 86 |
+
`get_tensor_layout("weight1")` should return a clean `Error::InvalidExternalData` for an out-of-range `scalar_type`, matching the behavior of the equivalent `.pte` `Tensor` parsing path.
|
| 87 |
+
|
| 88 |
+
### Actual result — verified against the pristine, unmodified ExecuTorch 1.3.1 source
|
| 89 |
+
|
| 90 |
+
Full symbolized stack trace (via `addr2line` against the built binary):
|
| 91 |
+
|
| 92 |
+
```
|
| 93 |
+
et_pal_abort
|
| 94 |
+
runtime/platform/default/posix.cpp:98
|
| 95 |
+
executorch::runtime::pal_abort()
|
| 96 |
+
runtime/platform/platform.cpp:126
|
| 97 |
+
executorch::runtime::runtime_abort()
|
| 98 |
+
runtime/platform/abort.cpp:20
|
| 99 |
+
executorch::runtime::TensorLayout::create(...)
|
| 100 |
+
runtime/core/exec_aten/util/scalar_type_util.h:419 <- elementSize()'s ET_CHECK_MSG
|
| 101 |
+
executorch::extension::(anonymous namespace)::create_tensor_layout(...)
|
| 102 |
+
extension/flat_tensor/flat_tensor_data_map.cpp:104
|
| 103 |
+
executorch::extension::FlatTensorDataMap::get_tensor_layout(...)
|
| 104 |
+
extension/flat_tensor/flat_tensor_data_map.cpp:122
|
| 105 |
+
LLVMFuzzerTestOneInput
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
```
|
| 109 |
+
==<pid>== ERROR: libFuzzer: deadly signal
|
| 110 |
+
#0 ... (abort machinery)
|
| 111 |
+
...
|
| 112 |
+
NOTE: libFuzzer has rudimentary signal handlers.
|
| 113 |
+
Combine libFuzzer with AddressSanitizer or similar for better crash reports.
|
| 114 |
+
SUMMARY: libFuzzer: deadly signal
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
**Reproduced 3/3 identical runs against the pristine source** (re-verified live for this report, with full symbol resolution confirming the exact call chain above).
|
| 118 |
+
|
| 119 |
+
## Impact
|
| 120 |
+
|
| 121 |
+
**Who is affected:** Any application calling `get_tensor_layout()`/`load_data_into()` on a `NamedData` entry whose `tensor_layout.scalar_type` is out of range.
|
| 122 |
+
|
| 123 |
+
**What the attacker can do:** Cause a deterministic crash — and notably, unlike the UBSan-trapped null-dereference findings in this codebase, this is a **deliberate `abort()` call that fires identically in production (non-sanitized) builds**, not merely undefined behavior that happens to crash under a sanitizer. This makes it a slightly stronger, more production-relevant DoS guarantee than the other findings in this batch.
|
| 124 |
+
|
| 125 |
+
**What's at risk:** Availability only. No memory corruption, no code execution — `ET_CHECK_MSG` performs a controlled, deliberate process termination.
|
| 126 |
+
|
| 127 |
+
**Why not Critical:** A deliberate `abort()`, not memory corruption or code execution.
|
| 128 |
+
|
| 129 |
+
## Suggested Remediation
|
| 130 |
+
|
| 131 |
+
```cpp
|
| 132 |
+
Result<const TensorLayout> create_tensor_layout(
|
| 133 |
+
const flat_tensor_flatbuffer::TensorLayout* tensor_layout) {
|
| 134 |
+
if (tensor_layout == nullptr) {
|
| 135 |
+
return Error::InvalidExternalData;
|
| 136 |
+
}
|
| 137 |
+
ScalarType scalar_type = static_cast<ScalarType>(tensor_layout->scalar_type());
|
| 138 |
+
if (!executorch::runtime::isValid(scalar_type)) {
|
| 139 |
+
return Error::InvalidExternalData;
|
| 140 |
+
}
|
| 141 |
+
const int dim = tensor_layout->sizes()->size();
|
| 142 |
+
...
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
This is a direct application of the pattern already correctly implemented in `tensor_parser_exec_aten.cpp`'s `parseTensor()` for the parallel `.pte` `Tensor` type — no new design is needed, just consistency between the two code paths.
|
| 146 |
+
|
| 147 |
+
A regression test should build a `.ptd` `NamedData.tensor_layout` with an out-of-range `scalar_type` byte and assert `get_tensor_layout()` returns a clean `Error` rather than aborting.
|
| 148 |
+
|
| 149 |
+
## Files Included in This Report
|
| 150 |
+
|
| 151 |
+
- `poc/poc_invalid_scalar_type.ptd` — the 272-byte PoC file (sha256 `b5972dad3d9e5cf23434270c1dadc2a03dd51b3c4fde8661b38f1e8a1e9494fd`)
|
| 152 |
+
- `poc/harness_flat_tensor_fuzzer.cpp` — the harness used to trigger and reproduce the crash
|
| 153 |
+
|
| 154 |
+
## huntr Submission Note
|
| 155 |
+
|
| 156 |
+
Per the huntr MFV program's submission requirements, this PoC needs to be uploaded to a public HuggingFace repository before filing. `poc/poc_invalid_scalar_type.ptd` is ready for that upload.
|
poc/harness_flat_tensor_fuzzer.cpp
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// libFuzzer harness for executorch::extension::FlatTensorDataMap::load()
|
| 2 |
+
// Targets the .ptd flatbuffer parsing path (extension/flat_tensor/flat_tensor_data_map.cpp).
|
| 3 |
+
// Authorized local testing only - huntr MFV scope: ExecuTorch .pte/.ptd parser.
|
| 4 |
+
|
| 5 |
+
#include <cstddef>
|
| 6 |
+
#include <cstdint>
|
| 7 |
+
|
| 8 |
+
#include <executorch/extension/data_loader/buffer_data_loader.h>
|
| 9 |
+
#include <executorch/extension/flat_tensor/flat_tensor_data_map.h>
|
| 10 |
+
#include <executorch/runtime/platform/runtime.h>
|
| 11 |
+
|
| 12 |
+
using executorch::extension::BufferDataLoader;
|
| 13 |
+
using executorch::extension::FlatTensorDataMap;
|
| 14 |
+
|
| 15 |
+
static bool g_initialized = false;
|
| 16 |
+
|
| 17 |
+
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size) {
|
| 18 |
+
if (!g_initialized) {
|
| 19 |
+
executorch::runtime::runtime_init();
|
| 20 |
+
g_initialized = true;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
constexpr std::size_t kMaxInput = 32U * 1024U * 1024U;
|
| 24 |
+
if (data == nullptr || size == 0 || size > kMaxInput) {
|
| 25 |
+
return 0;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
BufferDataLoader loader(data, size);
|
| 29 |
+
auto map = FlatTensorDataMap::load(&loader);
|
| 30 |
+
if (!map.ok()) {
|
| 31 |
+
return 0;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
auto& m = map.get();
|
| 35 |
+
auto num_keys_res = m.get_num_keys();
|
| 36 |
+
if (num_keys_res.ok()) {
|
| 37 |
+
uint32_t n = num_keys_res.get();
|
| 38 |
+
// Bound the loop - malicious n could be huge but get_key() range-checks it.
|
| 39 |
+
uint32_t iter = n > 4096 ? 4096 : n;
|
| 40 |
+
for (uint32_t i = 0; i < iter; ++i) {
|
| 41 |
+
auto key_res = m.get_key(i);
|
| 42 |
+
if (key_res.ok()) {
|
| 43 |
+
auto layout = m.get_tensor_layout(executorch::aten::string_view(key_res.get()));
|
| 44 |
+
if (layout.ok()) {
|
| 45 |
+
(void)layout.get().nbytes();
|
| 46 |
+
}
|
| 47 |
+
auto data_res = m.get_data(executorch::aten::string_view(key_res.get()));
|
| 48 |
+
if (data_res.ok()) {
|
| 49 |
+
data_res.get().Free();
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
return 0;
|
| 56 |
+
}
|
poc/poc_invalid_scalar_type.ptd
ADDED
|
Binary file (272 Bytes). View file
|
|
|