-
Notifications
You must be signed in to change notification settings - Fork 377
BufferOverflow Hardening #1896
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
Abdullah-Ebryx
wants to merge
2
commits into
containers:main
Choose a base branch
from
Abdullah-Ebryx:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
BufferOverflow Hardening #1896
+23
−23
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Reviewer's guide (collapsed on small PRs)Reviewer's GuideIntroduces a size parameter to chroot_realpath and updates its implementation and all callers to use explicit buffer lengths for safer path resolution. Class diagram for updated chroot_realpath function signature and usageclassDiagram
class chroot_realpath {
+char *chroot_realpath(const char *chroot, const char *path, char resolved_path[], size_t size_resolved_path)
}
class libcrun_container_checkpoint_linux_criu {
+calls chroot_realpath(..., buf, sizeof(buf))
}
class libcrun_container_restore_linux_criu {
+calls chroot_realpath(..., buf, sizeof(buf))
}
class safe_openat_fallback {
+calls chroot_realpath(..., buffer, sizeof(buffer))
}
libcrun_container_checkpoint_linux_criu --> chroot_realpath
libcrun_container_restore_linux_criu --> chroot_realpath
safe_openat_fallback --> chroot_realpath
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/libcrun/chroot_realpath.c:138` </location>
<code_context>
/* If a component doesn't exist, then return what we could translate. */
if (errno == ENOENT) {
- int ret = snprintf (resolved_path, PATH_MAX, "%s%s%s", got_path, path[0] == '/' || path[0] == '\0' ? "" : "/", path);
+ int ret = snprintf (resolved_path, size_resolved_path, "%s%s%s", got_path, path[0] == '/' || path[0] == '\0' ? "" : "/", path);
if (ret >= PATH_MAX) {
__set_errno(ENAMETOOLONG);
</code_context>
<issue_to_address>
**issue (bug_risk):** snprintf return value should be compared to size_resolved_path, not PATH_MAX.
Update the condition to 'if (ret >= size_resolved_path)' to ensure truncation is checked against the actual buffer size, avoiding incorrect results when size_resolved_path is less than PATH_MAX.
</issue_to_address>
### Comment 2
<location> `tests/tests_libcrun_fuzzer.c:126` </location>
<code_context>
if (path == NULL)
return 0;
- chroot_realpath (".", path, resolved_path);
+ chroot_realpath (".", path, resolved_path,sizeof(resolved_path));
(void) resolved_path;
return 0;
</code_context>
<issue_to_address>
**suggestion (testing):** No explicit test for small buffer sizes or buffer overflow conditions.
Please add tests that pass small buffer sizes to chroot_realpath to verify it handles these cases safely and returns appropriate errors.
</issue_to_address>
### Comment 3
<location> `tests/tests_libcrun_fuzzer.c:114` </location>
<code_context>
# endif
/* Defined in chroot_realpath.c */
-char *chroot_realpath (const char *chroot, const char *path, char resolved_path[]);
+char *chroot_realpath (const char *chroot, const char *path, char resolved_path[],size_t size_resolved_path);
static const char *console_socket = NULL;
</code_context>
<issue_to_address>
**suggestion (testing):** Fuzzer test does not assert or check the result of chroot_realpath.
Add assertions or checks for chroot_realpath's return value and errno, particularly with edge-case buffer sizes, to improve test coverage and catch regressions.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added a new argument to chroot_realpath to support small buffers.
As discussed in the previous pull request, this change helps avoid technical debt and enforces a security boundary by design, rather than relying on the programmer to implement it correctly.
Summary by Sourcery
Harden chroot_realpath against buffer overflows by adding an explicit buffer size parameter to its signature, updating all callers and the test harness to supply buffer length, and using the size in snprintf.
Enhancements:
Tests: