-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Adjust rm & du to use safe traversal (openat, unlinkat, etc) #8517
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
Conversation
|
i am pretty sure it is going to regress some GNU tests! |
|
GNU testsuite comparison: |
e5bc6c6 to
7a0d86f
Compare
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
89e50bb to
ad268a0
Compare
|
GNU testsuite comparison: |
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
This PR implements safe directory traversal for the rm and du utilities on Linux using openat(), unlinkat(), and related syscalls to avoid TOCTOU (Time-of-Check-Time-of-Use) race conditions. The implementation provides protection against filesystem race attacks by using file descriptors instead of paths for operations.
- Linux-specific safe traversal module added with RAII file descriptor management
rmupdated to use safe traversal for long paths (>1000 characters) to prevent path length issuesduupdated with safe traversal implementation that avoids symlink-related race conditions
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| util/build-gnu.sh | Skip GNU test that relies on race conditions safe traversal prevents |
| tests/by-util/test_rm.rs | Add test for recursive removal with long paths using safe traversal |
| tests/by-util/test_du.rs | Add comprehensive tests for safe traversal edge cases and symlink handling |
| src/uucore/src/lib/lib.rs | Export safe_traversal module when feature is enabled |
| src/uucore/src/lib/features/safe_traversal.rs | Core safe traversal implementation with DirFd wrapper |
| src/uucore/src/lib/features.rs | Declare safe_traversal module |
| src/uucore/Cargo.toml | Add safe-traversal feature flag |
| src/uu/rm/src/rm.rs | Implement safe directory removal for long paths on Linux |
| src/uu/rm/Cargo.toml | Enable safe-traversal feature |
| src/uu/du/src/du.rs | Implement safe directory traversal with cycle detection |
| src/uu/du/Cargo.toml | Enable safe-traversal feature |
Comments suppressed due to low confidence (1)
src/uucore/src/lib/features/safe_traversal.rs:1
- Using
/as a fallback metadata source will provide incorrect file type and size information. This could lead to incorrect behavior when the fake metadata is used for file operations. Consider returning an error instead of providing misleading metadata.
// Safe directory traversal using openat() and related syscalls
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
GNU testsuite comparison: |
|
Are the tests supposed to pass even without applying any of the changes to the other files? |
|
yeah |
cakebaker
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.
Done :)
|
i have some intermittent issues with this PR: |
|
GNU testsuite comparison: |
|
Sorry, there is a conflict :| |
|
GNU testsuite comparison: |
d06d00c to
8c4ff95
Compare
|
GNU testsuite comparison: |
8c4ff95 to
c9c64c5
Compare
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
beddf31 to
36bfdd3
Compare
|
GNU testsuite comparison: |
017a040 to
a7a5126
Compare
|
GNU testsuite comparison: |
Great :) |
I have other for chmod, chown & cp
For now, I am only modifying Linux. It would be too hard to update all of them at once I think.