-
Notifications
You must be signed in to change notification settings - Fork 815
Stack buffer overflow in prepare_input_tensors() due to unchecked memcpy size #16797
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: main
Are you sure you want to change the base?
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/16797
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New FailureAs of commit 9c75403 with merge base 86b4bea ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Mitigates a stack buffer overflow risk in prepare_input_tensors() by validating scalar input buffer sizes before copying into stack-allocated variables.
Changes:
- Add strict size checks for
Tag::Int(int64_t),Tag::Double(double), andTag::Bool(bool) inputs prior tomemcpy. - Return
InvalidArgumentwith a descriptive error when the provided scalar buffer size is unexpected.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Can you add a regression test? |
b0e5c6d to
8c8d7dc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8c8d7dc to
c621f13
Compare
c621f13 to
33aa861
Compare
33aa861 to
8090b55
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@mergennachin added one for double. Feel like that should be OK as it's the same logic, and adding tests for bool/int would need new models to |
larryliu0820
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some non-blocking comments
8090b55 to
801f5a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
801f5a3 to
e95bc65
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const char* add_path = std::getenv("ET_MODULE_ADD_PATH"); | ||
| Result<FileDataLoader> add_loader = FileDataLoader::from(add_path); | ||
| ASSERT_EQ(add_loader.error(), Error::Ok); | ||
| add_loader_ = std::make_unique<FileDataLoader>(std::move(add_loader.get())); | ||
|
|
||
| Result<Program> add_program = Program::load( | ||
| add_loader_.get(), Program::Verification::InternalConsistency); | ||
| ASSERT_EQ(add_program.error(), Error::Ok); | ||
| add_program_ = std::make_unique<Program>(std::move(add_program.get())); | ||
|
|
||
| add_mmm_ = std::make_unique<ManagedMemoryManager>( | ||
| /*planned_memory_bytes=*/32 * 1024U, | ||
| /*method_allocator_bytes=*/32 * 1024U); | ||
|
|
||
| Result<Method> add_method = | ||
| add_program_->load_method("forward", &add_mmm_->get()); | ||
| ASSERT_EQ(add_method.error(), Error::Ok); | ||
| add_method_ = std::make_unique<Method>(std::move(add_method.get())); | ||
|
|
||
| // Load ModuleIntBool | ||
| const char* intbool_path = std::getenv("ET_MODULE_INTBOOL_PATH"); | ||
| Result<FileDataLoader> intbool_loader = FileDataLoader::from(intbool_path); | ||
| ASSERT_EQ(intbool_loader.error(), Error::Ok); |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SetUp() assumes the environment variables are present. If ET_MODULE_ADD_PATH/ET_MODULE_INTBOOL_PATH are missing, the failure will show up later as a generic FileDataLoader::from() error. Adding ASSERT_NE(getenv(...), nullptr) for each path would make failures much easier to diagnose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think it's probably fine to have the filedataloader error show up.
e95bc65 to
1f63405
Compare
1f63405 to
9c75403
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Double is size 8; use a larger buffer to invoke overflow. | ||
| char large_buffer[16]; | ||
| memcpy(large_buffer, &alpha, sizeof(double)); | ||
|
|
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file now calls memcpy() directly; consider adding an explicit #include <cstring> (and #include <cstdlib> for std::getenv) to avoid relying on transitive includes for C library declarations.
| { | ||
| std::vector<std::pair<char*, size_t>> input_buffers; | ||
|
|
||
| char int_buffer[8]; |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid the magic constant 8 for the int buffer size; use sizeof(int64_t) (or sizeof(y)) so the test stays consistent with the production check (buffer_size != sizeof(int64_t)).
| char int_buffer[8]; | |
| char int_buffer[sizeof(int64_t)]; |
| const char* add_path = std::getenv("ET_MODULE_ADD_PATH"); | ||
| Result<FileDataLoader> add_loader = FileDataLoader::from(add_path); | ||
| ASSERT_EQ(add_loader.error(), Error::Ok); |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::getenv("ET_MODULE_ADD_PATH") can return nullptr; passing that into FileDataLoader::from() just yields a generic "File name cannot be empty" failure. Add an ASSERT_NE(add_path, nullptr) (ideally mentioning the env var name) before calling FileDataLoader::from() to make misconfigured test environments easier to debug.
| add_method_ = std::make_unique<Method>(std::move(add_method.get())); | ||
|
|
||
| // Load ModuleIntBool | ||
| const char* intbool_path = std::getenv("ET_MODULE_INTBOOL_PATH"); |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above for ET_MODULE_INTBOOL_PATH: add an ASSERT_NE(intbool_path, nullptr) (with a helpful message) before calling FileDataLoader::from() so failures clearly indicate a missing env var.
| const char* intbool_path = std::getenv("ET_MODULE_INTBOOL_PATH"); | |
| const char* intbool_path = std::getenv("ET_MODULE_INTBOOL_PATH"); | |
| ASSERT_NE(intbool_path, nullptr) | |
| << "ET_MODULE_INTBOOL_PATH environment variable must be set"; |
Summary
Add size checks for int, double, bool before memcpying. Otherwise the input buffer may be larger than the intended size and overwrite adjacent memory.
Test Plan