tsk-arasu commited on
Commit
c6c65e3
·
verified ·
1 Parent(s): 79cd35a

Upload folder using huggingface_hub

Browse files
REPORT.md ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Null Pointer Dereference in ExecuTorch FlatTensorDataMap::get_key() via Missing NamedData.key (.ptd)
2
+
3
+ **Target:** ExecuTorch 1.3.1 (.ptd, huntr Model File Vulnerability program)
4
+ **Severity:** Low-Medium (Denial of Service)
5
+ **CWE:** CWE-476 (NULL Pointer Dereference)
6
+ **Component:** `extension/flat_tensor/flat_tensor_data_map.cpp`
7
+ **Authentication Required:** No — only requires a victim application to load an attacker-supplied `.ptd` file and call a public enumeration API.
8
+
9
+ ## Summary
10
+
11
+ `FlatTensorDataMap::get_key()` is a public API for enumerating the names of tensors/blobs stored in a `.ptd` file by index — the standard pattern for an application to discover what data a file contains before requesting it by name. It dereferences `NamedData.key` without checking it for null, even though `key` is an ordinary (non-required) field in the schema. A `.ptd` file with a `NamedData` entry present in the `named_data` vector (so it is counted by `get_num_keys()`) but whose own `key` field is omitted crashes any process that enumerates keys by index — a completely standard, expected usage pattern, not an edge case.
12
+
13
+ **Confirmed against the pristine, unmodified ExecuTorch 1.3.1 source.**
14
+
15
+ ## Vulnerability Details
16
+
17
+ `extension/flat_tensor/serialize/flat_tensor.fbs`:
18
+
19
+ ```
20
+ table NamedData {
21
+ key: string; // not required
22
+ segment_index: uint32;
23
+ tensor_layout: TensorLayout;
24
+ }
25
+ ```
26
+
27
+ `extension/flat_tensor/flat_tensor_data_map.cpp` (pristine 1.3.1 source, lines 197–211):
28
+
29
+ ```cpp
30
+ ET_NODISCARD Result<uint32_t> FlatTensorDataMap::get_num_keys() const {
31
+ return flat_tensor_->named_data()->size();
32
+ }
33
+
34
+ ET_NODISCARD Result<const char*> FlatTensorDataMap::get_key(
35
+ uint32_t index) const {
36
+ uint32_t num_keys = get_num_keys().get();
37
+ ET_CHECK_OR_RETURN_ERROR(
38
+ index >= 0 && index < num_keys,
39
+ InvalidArgument,
40
+ "Index %u out of range of size %u",
41
+ index,
42
+ num_keys);
43
+ return flat_tensor_->named_data()->Get(index)->key()->c_str(); // <-- crash site, line 201 (offset within function)
44
+ }
45
+ ```
46
+
47
+ `FlatTensorDataMap::load()`'s validation only checks that the `named_data` **vector itself** is non-null at the top level — it never inspects the fields of individual `NamedData` elements. `get_named_data()` (the linear-search helper backing `get_tensor_layout()`/`get_data()`/`load_data_into()`) happens to implicitly avoid crashing on a null `key` in some cases due to how its comparison is structured, but `get_key()` is a **completely separate, simpler code path** that enumerates by index directly — it does not go through `get_named_data()` at all, so it inherits none of that incidental behavior.
48
+
49
+ ## Steps to Reproduce
50
+
51
+ ### Environment
52
+ Linux x86-64, ExecuTorch 1.3.1 pristine source, clang-16, CMake, Ninja. No authentication, no host access.
53
+
54
+ ### 1. Build ExecuTorch with sanitizers
55
+
56
+ Same build as REPORT-01 Step 1 (`EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON`).
57
+
58
+ ### 2. Build the harness (`poc/harness_flat_tensor_fuzzer.cpp`, included — identical to REPORT-01's harness, which already calls `get_key()` for every index up to `get_num_keys()`)
59
+
60
+ ```bash
61
+ export ET_PARENT=/path/to/parent-of-executorch
62
+ C10_INC="$ET_SRC/runtime/core/portable_type/c10"
63
+ INCLUDES="-I$ET_PARENT -I$ET_BUILD -I$ET_BUILD/schema/include -I$ET_BUILD/extension/flat_tensor/include -I$ET_BUILD/third-party/flatc_ep/include -I$C10_INC"
64
+
65
+ clang++-16 -std=c++17 -fsanitize=fuzzer,address,undefined -fno-omit-frame-pointer -fno-sanitize-recover=all \
66
+ $INCLUDES -DFLATBUFFERS_MAX_ALIGNMENT=1024 -DC10_USING_CUSTOM_GENERATED_MACROS \
67
+ -c poc/harness_flat_tensor_fuzzer.cpp -o harness.o
68
+
69
+ clang++-16 -fsanitize=fuzzer,address,undefined -o poc_harness harness.o \
70
+ "$ET_BUILD/extension/flat_tensor/libextension_flat_tensor.a" \
71
+ "$ET_BUILD/extension/data_loader/libextension_data_loader.a" \
72
+ "$ET_BUILD/libexecutorch_core.a"
73
+ ```
74
+
75
+ ### 3. PoC file
76
+
77
+ `poc/poc_get_key_null.ptd` (272 bytes, **included in this report — sha256 `427bc13020be820b41aafec2c6e00de360fe97185d3879d5ec770594c21ac39`**) contains a `named_data` vector with at least one `NamedData` entry whose `key` field is omitted.
78
+
79
+ ### 4. Trigger the crash
80
+
81
+ ```bash
82
+ export ASAN_OPTIONS="abort_on_error=1:symbolize=0"
83
+ export UBSAN_OPTIONS="halt_on_error=1:print_stacktrace=0"
84
+ ./poc_harness -timeout=5 -runs=0 poc/poc_get_key_null.ptd
85
+ ```
86
+
87
+ ### Expected result (secure behavior)
88
+ `get_key()` should return a clean `Error` (e.g. `InvalidExternalData`) for an entry with no `key`, rather than crashing.
89
+
90
+ ### Actual result — verified against the pristine, unmodified ExecuTorch 1.3.1 source
91
+
92
+ ```
93
+ Running: poc/poc_get_key_null.ptd
94
+ extension/flat_tensor/flat_tensor_data_map.cpp:201:57: runtime error: member call on null pointer of type 'flatbuffers::String'
95
+ SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior extension/flat_tensor/flat_tensor_data_map.cpp:201:57 in
96
+ ==<pid>== ERROR: libFuzzer: deadly signal
97
+ ```
98
+
99
+ **Reproduced 3/3 identical runs against the pristine source** (re-verified live for this report):
100
+ ```
101
+ run 1: extension/flat_tensor/flat_tensor_data_map.cpp:201:57: runtime error: member call on null pointer of type 'flatbuffers::String'
102
+ run 2: (identical)
103
+ run 3: (identical)
104
+ ```
105
+
106
+ ## Impact
107
+
108
+ **Who is affected:** Any application enumerating tensor/blob names in a `.ptd` file via `get_num_keys()` + `get_key()` — the standard discovery pattern for this format.
109
+
110
+ **What the attacker can do:** Cause a deterministic crash simply by having one entry in the `named_data` vector with no `key` — the file still loads successfully (the vector itself is present), so the crash only surfaces during ordinary enumeration.
111
+
112
+ **What's at risk:** Availability only.
113
+
114
+ **Why not Critical:** Controlled null-pointer dereference, no memory corruption or code execution.
115
+
116
+ ## Suggested Remediation
117
+
118
+ ```cpp
119
+ ET_NODISCARD Result<const char*> FlatTensorDataMap::get_key(
120
+ uint32_t index) const {
121
+ uint32_t num_keys = get_num_keys().get();
122
+ ET_CHECK_OR_RETURN_ERROR(
123
+ index >= 0 && index < num_keys,
124
+ InvalidArgument,
125
+ "Index %u out of range of size %u",
126
+ index,
127
+ num_keys);
128
+ auto* named_data = flat_tensor_->named_data()->Get(index);
129
+ ET_CHECK_OR_RETURN_ERROR(
130
+ named_data != nullptr && named_data->key() != nullptr,
131
+ InvalidExternalData,
132
+ "NamedData entry %u or its key is null",
133
+ index);
134
+ return named_data->key()->c_str();
135
+ }
136
+ ```
137
+
138
+ **Design recommendation:** this is one of several findings in this file (see companion reports on `get_tensor_layout()`/`create_tensor_layout()`) where the file validates the top-level presence of `named_data`/`segments` vectors at `load()` time but never validates the fields within each element. A single validation pass over `named_data()` at load time — or a shared per-entry validator called from every accessor — would close this entire class of findings at once rather than requiring a separate patch per accessor as each is independently discovered.
139
+
140
+ A regression test should build a `.ptd` with a `NamedData` entry that has `key` omitted, asserting `get_key()` returns a clean `Error` rather than crashing.
141
+
142
+ ## Files Included in This Report
143
+
144
+ - `poc/poc_get_key_null.ptd` — the 272-byte PoC file (sha256 `427bc13020be820b41aafec2c6e00de360fe97185d3879d5ec770594c21ac39`)
145
+ - `poc/harness_flat_tensor_fuzzer.cpp` — the harness used to trigger and reproduce the crash (same binary as REPORT-01/02/04, which all target `extension/flat_tensor/flat_tensor_data_map.cpp`)
146
+
147
+ ## huntr Submission Note
148
+
149
+ Per the huntr MFV program's submission requirements, this PoC needs to be uploaded to a public HuggingFace repository before filing. `poc/poc_get_key_null.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_get_key_null.ptd ADDED
Binary file (272 Bytes). View file