You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a702383
Browse filesBrowse the repository at this point in the historyBrowse files
Arm backend: bounds-check the Ethos-U vela_bin_stream parser (pytorch#22580)
# Arm backend: bounds-check the Ethos-U vela_bin_stream parser
### Summary
`vela_bin_read()` trusted the per-block `size` field and the
`inputs`/`outputs`
descriptor sizes from the Ethos-U delegate blob without validating them
against
the buffer, so a malformed or corrupt blob could read or write out of
bounds
while parsing at load time and while copying into the scratch buffer at
execute
time. This adds the missing bounds validation, matching the
untrusted-delegate-blob
hardening already present in the XNNPACK, Vulkan and Qualcomm backends.
### What changed (suggested review order)
1. `backends/arm/runtime/VelaBinStream.cpp`
- Require a full `VelaBinBlock` header to remain before reading a block,
and
reject a block whose payload does not fit in the remaining buffer. The
raw
`size` is checked in `size_t` **before** the 16-byte padding, because
`next_mul_16()` is computed in `uintptr_t` and wraps to 0 for sizes near
`UINT32_MAX` on 32-bit targets (Cortex-M).
- `bind_io_block()`: validate that an `inputs`/`outputs` payload holds
its
declared `count` of `VelaIO` entries (and `count >= 0`) before the
`reinterpret_cast`.
- Size-check the `scratch_size` and `cmd_data` payloads before reading
them.
- `vela_bin_validate()`: reject a blob smaller than one block header
before
computing `foot = data + size - sizeof(VelaBinBlock)` (which otherwise
underflows below `data`).
2. `backends/arm/runtime/EthosUBackend.cpp` — reject
`input_count`/`output_count`
that overrun the `args` span, and bound the input scratch `offset +
nbytes`
against `scratch_data_size` before the copy.
3. `backends/arm/runtime/EthosUBackend_Cortex_M.cpp` — bound the output
scratch
`offset + tensor_bytes` against `scratch_data_size` before the copy.
4. `backends/arm/test/vela_external_blocks_test.cpp` — add negative
tests
(truncated header, block size larger than buffer, IO count exceeding
payload)
and size the existing IO-block test payloads to hold their declared
`count`.
### Testing
- Added the negative parser tests above; existing `VelaExternalBlocks`
tests
still pass by construction (the IO-block payloads were resized to match
the new
validation).
- Note: I was unable to build/run the suite in my environment (no local
C++
toolchain for the Arm runtime); relying on CI. Please run the
`backends/arm` runtime tests.
Fixespytorch#22579
---
This PR was authored with assistance from Claude Code.
cc @digantdesai@freddan80@per@zingo@oscarandersson8218@mansnils@Sebastian-Larsson@robell@rascani@nil-is-all
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
0 commit comments