Skip to content

Cap num_externs to 4096#18909

Open
lucylq wants to merge 1 commit intopytorch:mainfrom
lucylq:export-D100822659
Open

Cap num_externs to 4096#18909
lucylq wants to merge 1 commit intopytorch:mainfrom
lucylq:export-D100822659

Conversation

@lucylq
Copy link
Copy Markdown
Contributor

@lucylq lucylq commented Apr 15, 2026

Summary:
num_externs counts the number of external values that xnnpack receives from the runtime, in the form of arguments. It's taken from the flatbuffer file and used to allocate an internal array.

Attack vector: num_externs in flatbuffer is overwritten to a large number, causing large, oob allocations.

The value of externs is per delegate blob - it's super unlikely to have 4096 allocs, probably expect single digits normally.

Note: there's not a particularly good way to verify the value, as num_externs contains input, output and non-parameters (such as symbolic shapes). Input, output are consumed by the delegate, but symbolic shapes are not, but are passed in anyways. So the flatbuffer doesn't have information to calculate the real total.

Reviewed By: GregoryComer

Differential Revision: D100822659

Summary:
num_externs counts the number of external values that xnnpack receives from the runtime, in the form of arguments. It's taken from the flatbuffer file and used to allocate an internal array.

Attack vector: num_externs in flatbuffer is overwritten to a large number, causing large, oob allocations.

The value of externs is per delegate blob - it's super unlikely to have 4096 allocs, probably expect single digits normally.

Note: there's not a particularly good way to verify the value, as num_externs contains input, output and non-parameters (such as symbolic shapes). Input, output are consumed by the delegate, but symbolic shapes are not, but are passed in anyways. So the flatbuffer doesn't have information to calculate the real total.

Reviewed By: GregoryComer

Differential Revision: D100822659
@lucylq lucylq requested a review from digantdesai as a code owner April 15, 2026 18:54
Copilot AI review requested due to automatic review settings April 15, 2026 18:54
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Apr 15, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18909

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (2 Unrelated Failures)

As of commit 1a0aae0 with merge base f35fbb5 (image):

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 15, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync bot commented Apr 15, 2026

@lucylq has exported this pull request. If you are a Meta employee, you can view the originating Diff in D100822659.

@github-actions
Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a defensive validation in the XNNPACK runtime compiler to cap num_externs (read from the delegate flatbuffer) before creating the XNNPACK subgraph, mitigating corrupted/hostile blobs causing oversized allocations.

Changes:

  • Read num_externs once from the flatbuffer and validate it does not exceed 4096.
  • Return InvalidProgram with a descriptive error when num_externs is above the cap.
  • Pass the validated num_externs into xnn_create_subgraph.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1923 to +1925
"XNNPACK flatbuffer blob has num_externs (%u) which exceeds maximum (4096)."
" This likely indicates a corrupted or invalid serialized graph",
num_externs);
Comment on lines +1920 to +1924
ET_CHECK_OR_RETURN_ERROR(
num_externs <= 4096,
InvalidProgram,
"XNNPACK flatbuffer blob has num_externs (%u) which exceeds maximum (4096)."
" This likely indicates a corrupted or invalid serialized graph",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported security-fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants