Conversation
XNNCompiler::defineTensor forwarded the attacker-controlled `flags` field from the serialized XNNTensorValue straight to xnn_define_*_tensor_value. XNNPACK documents only two supported flag bits (XNN_VALUE_FLAG_EXTERNAL_INPUT, XNN_VALUE_FLAG_EXTERNAL_OUTPUT). Setting other bits confuses the runtime's ownership tracking so that xnn_delete_runtime later calls free() on a pointer that the host runtime allocated (for example, the planned-buffer block), producing a double free / invalid free. Reject any flag bit outside the supported mask with Error::InvalidProgram. TOB-EXECUTORCH-44.pte (flags 0xFFFFFF00, 0xFFFFFFFE) and TOB-EXECUTORCH-45.pte (flags 0x80100) are now rejected before the subgraph is built. Co-authored-by: Claude <noreply@anthropic.com>
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/19102
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ⏳ No Failures, 64 PendingAs of commit 3435980 with merge base 0919746 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
There was a problem hiding this comment.
Pull request overview
Adds validation to reject invalid XNNPACK tensor flag bits during XNNPACK graph compilation, preventing malformed PTEs from proceeding further into compilation.
Changes:
- Add an allowlist mask check for
XNNTensorValue.flagsindefineTensor. - Return
Error::InvalidProgram(with an error log) when unsupported flag bits are present.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ET_CHECK_OR_RETURN_ERROR( | ||
| (tensor_value->flags() & ~kAllowedFlagsMask) == 0, | ||
| InvalidProgram, | ||
| "Tensor value has unsupported flag bits 0x%x", | ||
| tensor_value->flags()); |
There was a problem hiding this comment.
The error log uses printf formatting; passing tensor_value->flags() (a FlatBuffers uint, i.e., uint32_t) to 0x%x can be undefined on platforms where uint32_t is not unsigned int (e.g., typedefs to unsigned long). Cast to the matching type or use an inttypes.h macro (e.g., print 0x%" PRIx32 "). Also consider logging the unsupported bits value (flags & ~kAllowedFlagsMask) rather than the full flags to make the message actionable.
Test Plan:
Build and run executor runner against problematic PTE file:
Previous
After, graceful error