-
Notifications
You must be signed in to change notification settings - Fork 374
chroot_realpath and tests: Replace sprintf with snprintf for security #1885
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
Reviewer's guide (collapsed on small PRs)Reviewer's GuideReplace all unsafe sprintf calls with snprintf using fixed buffer limits (sizeof buffers or PATH_MAX) across test initialization, fuzzer ID generation, and core chroot_realpath logic to mitigate potential buffer overflow vulnerabilities. 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 - here's some feedback:
- In chroot_realpath.c, consider replacing the hard-coded PATH_MAX with sizeof(resolved_path) or an explicit bufsize parameter to ensure snprintf’s size matches the actual buffer length.
- The change to the HF_ITER extern declaration in tests_libcrun_fuzzer.c looks like an unrelated formatting tweak—please revert or separate it into its own PR to keep the snprintf changes focused.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In chroot_realpath.c, consider replacing the hard-coded PATH_MAX with sizeof(resolved_path) or an explicit bufsize parameter to ensure snprintf’s size matches the actual buffer length.
- The change to the HF_ITER extern declaration in tests_libcrun_fuzzer.c looks like an unrelated formatting tweak—please revert or separate it into its own PR to keep the snprintf changes focused.
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Ephemeral COPR build failed. @containers/packit-build please check. |
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.
The first commit says "tests:" in the subject line but modifies src/libcrun/chroot_realpath.c.
In general, we are not interested in hardening tests security.
tests/tests_libcrun_fuzzer.c
Outdated
} | ||
#ifdef FUZZER | ||
extern void HF_ITER (uint8_t **buf, size_t *len); | ||
extern void HF_ITER (uint8_t * *buf, size_t * len); |
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.
What is this for?
tests/init.c
Outdated
{ | ||
/* change one page each 0.1 seconds */ | ||
nanosleep ((const struct timespec[]) { { 0, 100000000L } }, NULL); | ||
nanosleep ((const struct timespec[]){ { 0, 100000000L } }, NULL); |
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.
What is this for?
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.
OK, this is really hard to review since you are modifying the single line in chroot_realpath.c in three subsequent commits. Marking this as draft for now; once ready for review, please click to "ready for review".
b302be8
to
11a40b1
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.
Hey there - I've reviewed your changes - here's some feedback:
- In chroot_realpath, verify snprintf’s return value to detect and handle any potential buffer truncation instead of assuming full writes.
- Prefer using sizeof(resolved_path) (the actual buffer length) instead of hardcoded PATH_MAX to keep snprintf size in sync with the buffer.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In chroot_realpath, verify snprintf’s return value to detect and handle any potential buffer truncation instead of assuming full writes.
- Prefer using sizeof(resolved_path) (the actual buffer length) instead of hardcoded PATH_MAX to keep snprintf size in sync with the buffer.
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@kolyshkin I forgot to rebase the commits, now should be ok. Please re-review. |
Replace sprintf with snprintf to prevent buffer overflows in chroot_realpath.c. This follows the security hardening mentioned in NEWS.md where sprintf was replaced with safer alternatives. The function uses PATH_MAX as the buffer size since sizeof on array function parameters returns the pointer size, not the actual buffer size. Signed-off-by: Osama Abdelkader <[email protected]>
Replace sprintf with snprintf in test files to prevent buffer overflows. This follows the security hardening mentioned in NEWS.md where sprintf was replaced with safer alternatives. Changes made: - tests/init.c: Replace sprintf with snprintf for proc paths - tests/tests_libcrun_fuzzer.c: Replace sprintf with snprintf for ID generation Signed-off-by: Osama Abdelkader <[email protected]>
11a40b1
to
ccbf0d9
Compare
Replace all instances of sprintf with snprintf to prevent buffer overflows. This follows the security hardening mentioned in NEWS.md where sprintf was replaced with safer alternatives.
Changes made:
All changes use appropriate buffer size limits to prevent overflow.
Summary by Sourcery
Harden string formatting across the project by replacing unsafe sprintf calls with bounded snprintf usages and explicit buffer size limits to prevent buffer overflows in both test code and core functionality.
Enhancements: