Skip to content

Fix integer overflow in Vulkan multiply_integers#18681

Open
lucylq wants to merge 1 commit intomainfrom
security27
Open

Fix integer overflow in Vulkan multiply_integers#18681
lucylq wants to merge 1 commit intomainfrom
security27

Conversation

@lucylq
Copy link
Copy Markdown
Contributor

@lucylq lucylq commented Apr 2, 2026

Replace std::accumulate with c10::mul_overflows to check for overflow at each multiplication.

Prevents undersized GPU buffer allocations from attacker-controlled tensor dimensions in PTE files.

This PR was authored with the assistance of Claude.

Test plan

CI

cc @SS-JIA @manuelcandales @digantdesai @cbilgin

Replace std::accumulate with std::multiplies<>() with an explicit loop
using safe_multiply_int64() that pre-checks for overflow before each
multiplication. Prevents undersized GPU buffer allocations from
attacker-controlled tensor dimensions in PTE files.

Addresses TOB-EXECUTORCH-27.

This PR was authored with the assistance of Claude.
@pytorch-bot pytorch-bot bot added the module: vulkan Issues related to the Vulkan delegate and code under backends/vulkan/ label Apr 2, 2026
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Apr 2, 2026

🔗 Helpful Links

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

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

❌ 8 New Failures, 1 Cancelled Job, 2 Unrelated Failures

As of commit 99b01c4 with merge base ee92757 (image):

NEW FAILURES - The following jobs have failed:

CANCELLED JOB - The following job was cancelled. Please retry:

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 2, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

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.

@lucylq lucylq marked this pull request as ready for review April 2, 2026 21:52
@lucylq lucylq requested a review from SS-JIA as a code owner April 2, 2026 21:52
Copilot AI review requested due to automatic review settings April 2, 2026 21:52
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

This PR hardens the Vulkan backend’s integer multiplication utility used for tensor size/numel calculations by adding per-step overflow detection, preventing undersized GPU buffer allocations when tensor dimensions are attacker-controlled (e.g., from PTE files).

Changes:

  • Add c10::mul_overflows-based overflow checking to multiply_integers (iterator overload).
  • Update the container overload to delegate to the iterator overload.
  • Add the necessary c10/util/safe_numerics.h include.

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


#include <cmath>
#include <limits>
#include <numeric>
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

<numeric> appears to be unused in this header after replacing std::accumulate with c10::mul_overflows. Consider removing the <numeric> include to avoid unnecessary dependencies/compile overhead.

Suggested change
#include <numeric>

Copilot uses AI. Check for mistakes.
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. module: vulkan Issues related to the Vulkan delegate and code under backends/vulkan/ security-fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants