Skip to content

Fix null-deref in parse_cond_value #12294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

psiddh
Copy link
Contributor

@psiddh psiddh commented Jul 8, 2025

Summary:
The crash is a null-deref that occurs in the parse_cond_value function when executing a JumpFalse instruction in the Executorch runtime. The crash happens because the program attempts to access the data pointer of a tensor without checking if it is null.

The root cause of the crash is that the parse_cond_value function does not validate if the tensor's data pointer is null before accessing its elements. This can happen when the input tensor is empty or its storage is not properly allocated. The function assumes that the tensor's data pointer is always valid, which is not the case when the tensor is empty.

The patch fixes the crash by adding a null check for the tensor's data pointer before accessing its elements. Specifically, it adds the following code: if (cond_data == nullptr) { ET_LOG(Error, "Tensor data is null"); return Error::InvalidArgument; }. This check ensures that the function returns an error when the tensor's data pointer is null, preventing the null-deref crash.

Other considerations that reviewers should take into account when validating the patch include verifying that the fix does not introduce any new errors or affect the normal execution of the Executorch runtime. Reviewers should also check that the patch handles edge cases, such as when the input tensor is not of type Bool or when the tensor is not properly initialized. Additionally, reviewers should ensure that the error handling mechanism is properly implemented and that the error message is informative and helpful for debugging purposes.

In particular, reviewers should verify that the ET_LOG statement is properly logging the error and that the Error::InvalidArgument return value is correctly handled by the calling function. They should also check that the fix does not affect the performance of the Executorch runtime or introduce any new security vulnerabilities.

NOTE: This diff is entirely auto-generated by LLM-based patch generator.
Reviewer should carefully examine this diff as Lionhead does not guarrantee the
correctnesss of the patch beyond fixing the crash and passing existing tests.
Please commandeer this diff and revise as needed. Our bot does not respond to
comments or revision requests (yet).

Differential Revision: D77827830

Summary:
The crash is a null-deref that occurs in the `parse_cond_value` function when executing a JumpFalse instruction in the Executorch runtime. The crash happens because the program attempts to access the data pointer of a tensor without checking if it is null.

The root cause of the crash is that the `parse_cond_value` function does not validate if the tensor's data pointer is null before accessing its elements. This can happen when the input tensor is empty or its storage is not properly allocated. The function assumes that the tensor's data pointer is always valid, which is not the case when the tensor is empty.

The patch fixes the crash by adding a null check for the tensor's data pointer before accessing its elements. Specifically, it adds the following code: `if (cond_data == nullptr) { ET_LOG(Error, "Tensor data is null"); return Error::InvalidArgument; }`. This check ensures that the function returns an error when the tensor's data pointer is null, preventing the null-deref crash.

Other considerations that reviewers should take into account when validating the patch include verifying that the fix does not introduce any new errors or affect the normal execution of the Executorch runtime. Reviewers should also check that the patch handles edge cases, such as when the input tensor is not of type `Bool` or when the tensor is not properly initialized. Additionally, reviewers should ensure that the error handling mechanism is properly implemented and that the error message is informative and helpful for debugging purposes.

In particular, reviewers should verify that the `ET_LOG` statement is properly logging the error and that the `Error::InvalidArgument` return value is correctly handled by the calling function. They should also check that the fix does not affect the performance of the Executorch runtime or introduce any new security vulnerabilities.

NOTE: This diff is entirely auto-generated by LLM-based patch generator.
Reviewer should carefully examine this diff as Lionhead does not guarrantee the
correctnesss of the patch beyond fixing the crash and passing existing tests.
Please commandeer this diff and revise as needed. Our bot does not respond to
comments or revision requests (yet).

Differential Revision: D77827830
Copy link

pytorch-bot bot commented Jul 8, 2025

🔗 Helpful Links

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

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

❌ 1 Cancelled Job, 19 Unrelated Failures

As of commit e79fd08 with merge base 6b3f172 (image):

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

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

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.

@facebook-github-bot facebook-github-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 Jul 8, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D77827830

Copy link

github-actions bot commented Jul 8, 2025

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
Contributor

@JacobSzwejbka JacobSzwejbka left a comment

Choose a reason for hiding this comment

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

Nice! Howd you run into this?

@@ -270,6 +270,10 @@ Result<bool> parse_cond_value(const EValue& cond_value) {
static_cast<int8_t>(cond_val.scalar_type()));

const bool* cond_data = cond_val.const_data_ptr<bool>();
if (cond_data == nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually can we use ET_CHECK_OR_RETURN_ERROR instead

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants