pytorch / pytorch/executorch

Kernels assume dim <= kTensorDimensionLimit

Open
#8,237 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

module: kernels triaged
Dominant language
Python
Stars
5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
581

Description

🐛 Describe the bug

While reviewing https://github.com/pytorch/executorch/pull/7943 it surfaced that a lot of kernels and kernel utilities assume that tensors will never have more than kTensorDimensionLimit, or in some cases defining their own values for kTensorDimensionLimit and not checking that the tensor dimensions are actually smaller than that value.

Nothing in the runtime today puts a limit on the number of dimensions of a tensor. It would be legal to construct a PTE file that contains a tensor with kTensorDimensionLimit + 1 dimensions, and it would be legal for a model to define an input with kTensorDimensionLimit + dimensions.

And even if the model's tensors fit within the assumed size, a PTE file could become corrupted in a way that increases a tensor's dimensions.

If a kernel or backend encountered a tensor with an unexpectedly-large number of dimensions, they may overrun stack-resident buffers, causing subtle or not-so-subtle problems, corruption, and crashes. It's also a potential security attack vector.

Auditing existing code is one step, followed by adding regression tests to ensure that fixes stay fixed.

Fuzzing is another important tool, along with tools like @manuelcandales's kernel testing tool. These would help us uncover unknown assumptions, and help us run regression tests against the code.

cc: @swolchok

Versions

ExecuTorch 0.5.0

cc @larryliu0820 @manuelcandales

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with runtime/core/exec_aten/util/tensor_util.h at kTensorDimensionLimit, then audit the kernels and kernel utilities for fixed-dimension assumptions and locally defined limits. Use the kernel testing tool and fuzzing where available, and add regression coverage so oversized or corrupted tensor dimensions are rejected without buffer overruns.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot, machine-learning, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.