Fix heap-buffer-overflow in constant_pad_nd#18018
Fix heap-buffer-overflow in constant_pad_nd#18018psiddh wants to merge 1 commit intopytorch:mainfrom
Conversation
Summary: Fix write-heap-buffer-overflow in set_all_to_value triggered via apply_padding_to_dim, reported by fuzzer (T258811544). Root causes: 1. Negative padding values silently cast to huge size_t, causing massive out-of-bounds writes. 2. When out_data advances past out_data_end, the remaining computation (out_data_end - out_data) wraps around to a huge size_t, causing bounds checks to incorrectly pass. 3. No error propagation after recursive apply_padding_to_dim calls, allowing the loop to continue writing after a child call has failed. Fixes: - Validate all padding values are non-negative in check_constant_pad_args. - Read padding as int64_t and explicitly check >= 0 before casting to size_t. - Guard remaining computation with out_data <= out_data_end check at all three bounds-check sites to prevent size_t wraparound. - Check ctx.failure_state() after recursive calls and bail out early. - Remove dead pad_i >= 0 check (always true for size_t). Closes T258811544 Differential Revision: D95762335
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18018
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New Failures, 1 Pending, 2 Unrelated FailuresAs of commit 19b6aef with merge base 08c3a72 ( NEW FAILURES - The following jobs have failed:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
There was a problem hiding this comment.
Pull request overview
Fixes a heap-buffer-overflow in the portable CPU implementation of aten.constant_pad_nd by hardening padding validation and preventing size/pointer arithmetic wraparound during padding application.
Changes:
- Validate that all padding values are non-negative in
check_constant_pad_args. - In the padding implementation, read padding as
int64_t, validate before casting tosize_t, and addout_data <= out_data_endguards before computing remaining space. - Propagate failures from recursive padding calls by bailing out early when
ctxenters a failure state.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| kernels/portable/cpu/util/kernel_ops_util.cpp | Adds argument validation rejecting negative padding values. |
| kernels/portable/cpu/op_constant_pad_nd.cpp | Hardens runtime padding application against wraparound and ensures failure propagation during recursion. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary:
Fix write-heap-buffer-overflow in set_all_to_value triggered via apply_padding_to_dim, reported by fuzzer (T258811544).
Root causes:
Fixes:
Differential Revision: D95762335