-
Notifications
You must be signed in to change notification settings - Fork 712
[llm_patch] Fix out-of-bounds access in pad2d function #15623
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
base: gh/lucylq/124/base
Are you sure you want to change the base?
Conversation
Add checks for pad1d and pad3d, as well as pad2d. --- The crash is a "wild-addr-read" that occurs in the `pad2d` function, which is part of the Executorch library. This type of crash typically indicates that the program is attempting to read from an invalid or uninitialized memory address. The root cause of the crash is an out-of-bounds access in the `pad2d` function. The function uses a `padding_ix` function to calculate indices for the input tensor `in`, but it does not perform sufficient bounds checking to ensure that these indices are valid. As a result, the program may attempt to read from memory outside the bounds of the `in` tensor, leading to the crash. The patch fixes the crash by adding bounds checking to the `pad2d` function. Specifically, it adds two `ET_CHECK` statements to verify that the indices calculated by `padding_ix` are within the valid range of the `in` tensor. The checks are performed using the following code: `ET_CHECK(in_h_idx < in_height)` and `ET_CHECK(in_w_idx < in_width)`. By adding these checks, the patch ensures that the program will not attempt to read from invalid memory addresses, preventing the "wild-addr-read" crash. Other considerations that reviewers should take into account when validating the patch include the potential impact on performance. The added `ET_CHECK` statements may introduce a small performance overhead, particularly if the `pad2d` function is called frequently. Reviewers should verify that the performance impact is acceptable and that the patch does not introduce any other unintended consequences. Additionally, reviewers should test the patch with a variety of input tensors and padding configurations to ensure that it correctly handles different edge cases. They should also verify that the `ET_CHECK` statements are triggered correctly when invalid indices are encountered, and that the program behaves as expected in these cases. 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: [D80831697](https://our.internmc.facebook.com/intern/diff/D80831697/) [ghstack-poisoned]
Add checks for pad1d and pad3d, as well as pad2d. --- The crash is a "wild-addr-read" that occurs in the `pad2d` function, which is part of the Executorch library. This type of crash typically indicates that the program is attempting to read from an invalid or uninitialized memory address. The root cause of the crash is an out-of-bounds access in the `pad2d` function. The function uses a `padding_ix` function to calculate indices for the input tensor `in`, but it does not perform sufficient bounds checking to ensure that these indices are valid. As a result, the program may attempt to read from memory outside the bounds of the `in` tensor, leading to the crash. The patch fixes the crash by adding bounds checking to the `pad2d` function. Specifically, it adds two `ET_CHECK` statements to verify that the indices calculated by `padding_ix` are within the valid range of the `in` tensor. The checks are performed using the following code: `ET_CHECK(in_h_idx < in_height)` and `ET_CHECK(in_w_idx < in_width)`. By adding these checks, the patch ensures that the program will not attempt to read from invalid memory addresses, preventing the "wild-addr-read" crash. Other considerations that reviewers should take into account when validating the patch include the potential impact on performance. The added `ET_CHECK` statements may introduce a small performance overhead, particularly if the `pad2d` function is called frequently. Reviewers should verify that the performance impact is acceptable and that the patch does not introduce any other unintended consequences. Additionally, reviewers should test the patch with a variety of input tensors and padding configurations to ensure that it correctly handles different edge cases. They should also verify that the `ET_CHECK` statements are triggered correctly when invalid indices are encountered, and that the program behaves as expected in these cases. 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: [D80831697](https://our.internmc.facebook.com/intern/diff/D80831697/) ghstack-source-id: 321204862 Pull Request resolved: #15623
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/15623
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 6 Unrelated FailuresAs of commit 5cab9ec with merge base 993254c ( NEW FAILURE - The following job has failed:
FLAKY - The following job failed but was likely due to flakiness present on trunk:
BROKEN TRUNK - The following jobs failed but was 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. |
This PR needs a
|
Stack from ghstack (oldest at bottom):
Add checks for pad1d and pad3d, as well as pad2d.
I think what happens is, we 'broadcast' the input tensor into the padded regions, depending on the pad algorithm (replication, reflection).
The pad algorithm takes an output tensor index, and returns an input tensor index. We need to check that this index is valid/within bounds of the input tensor.
The crash is a "wild-addr-read" that occurs in the
pad2dfunction, which is part of the Executorch library. This type of crash typically indicates that the program is attempting to read from an invalid or uninitialized memory address.The root cause of the crash is an out-of-bounds access in the
pad2dfunction. The function uses apadding_ixfunction to calculate indices for the input tensorin, but it does not perform sufficient bounds checking to ensure that these indices are valid. As a result, the program may attempt to read from memory outside the bounds of theintensor, leading to the crash.The patch fixes the crash by adding bounds checking to the
pad2dfunction. Specifically, it adds twoET_CHECKstatements to verify that the indices calculated bypadding_ixare within the valid range of theintensor. The checks are performed using the following code:ET_CHECK(in_h_idx < in_height)andET_CHECK(in_w_idx < in_width). By adding these checks, the patch ensures that the program will not attempt to read from invalid memory addresses, preventing the "wild-addr-read" crash.Other considerations that reviewers should take into account when validating the patch include the potential impact on performance. The added
ET_CHECKstatements may introduce a small performance overhead, particularly if thepad2dfunction is called frequently. Reviewers should verify that the performance impact is acceptable and that the patch does not introduce any other unintended consequences. Additionally, reviewers should test the patch with a variety of input tensors and padding configurations to ensure that it correctly handles different edge cases. They should also verify that theET_CHECKstatements are triggered correctly when invalid indices are encountered, and that the program behaves as expected in these cases.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: D80831697