-
-
Notifications
You must be signed in to change notification settings - Fork 168
fix(vfs): 当以相对路径 + dirfd 调用 openat/unlinkat 时,父目录被错误解析为 root 的问题。 #1355
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
fix(vfs): 当以相对路径 + dirfd 调用 openat/unlinkat 时,父目录被错误解析为 root 的问题。 #1355
Conversation
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 adds support for the unlink_test from the gvisor test suite and fixes several path handling issues in filesystem operations. The changes improve edge case handling for empty paths, trailing slashes, and parent directory lookups.
Key changes:
- Added
unlink_testto the gvisor test whitelist with a corresponding blocklist for unsupported test cases - Fixed parent directory lookup logic in
do_remove_dir,do_unlink_at, anddo_sys_openat2to handle cases whereparent_pathisNone - Added validation for empty paths and trailing slashes in
do_unlink_at - Added validation for empty paths and root directory in
do_remove_dir - Removed unused variable and unnecessary blank lines
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| user/apps/tests/syscall/gvisor/whitelist.txt | Adds unlink_test to the test whitelist |
| user/apps/tests/syscall/gvisor/blocklists/unlink_test | Creates blocklist for unsupported unlink_test cases requiring fchmod |
| kernel/src/syscall/user_access.rs | Removes unnecessary blank line |
| kernel/src/filesystem/vfs/vcore.rs | Fixes parent directory lookup logic and adds path validation for do_remove_dir and do_unlink_at |
| kernel/src/filesystem/vfs/open.rs | Fixes parent directory lookup logic in do_sys_openat2 and removes unused variable |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
kernel/src/filesystem/vfs/vcore.rs
Outdated
| inode_begin.clone() | ||
| } else { | ||
| inode_begin | ||
| .lookup_follow_symlink(parent_path.unwrap_or("/"), VFS_MAX_FOLLOW_SYMLINK_TIMES)? |
Copilot
AI
Nov 10, 2025
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 unwrap_or(\"/\") fallback on line 249 is unreachable since the else branch is only taken when parent_path.is_some(). Consider using unwrap() instead to make the code's intent clearer, or restructure the logic to avoid the unnecessary fallback.
| .lookup_follow_symlink(parent_path.unwrap_or("/"), VFS_MAX_FOLLOW_SYMLINK_TIMES)? | |
| .lookup_follow_symlink(parent_path.unwrap(), VFS_MAX_FOLLOW_SYMLINK_TIMES)? |
kernel/src/filesystem/vfs/vcore.rs
Outdated
| inode_begin.clone() | ||
| } else { | ||
| inode_begin | ||
| .lookup_follow_symlink(parent_path.unwrap_or("/"), VFS_MAX_FOLLOW_SYMLINK_TIMES)? |
Copilot
AI
Nov 10, 2025
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 unwrap_or(\"/\") fallback on line 286 is unreachable since the else branch is only taken when parent_path.is_some(). Consider using unwrap() instead to make the code's intent clearer, or restructure the logic to avoid the unnecessary fallback.
| .lookup_follow_symlink(parent_path.unwrap_or("/"), VFS_MAX_FOLLOW_SYMLINK_TIMES)? | |
| .lookup_follow_symlink(parent_path.unwrap(), VFS_MAX_FOLLOW_SYMLINK_TIMES)? |
kernel/src/filesystem/vfs/open.rs
Outdated
| inode_begin.clone() | ||
| } else { | ||
| inode_begin.lookup_follow_symlink( | ||
| parent_path.unwrap_or("/"), |
Copilot
AI
Nov 10, 2025
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 unwrap_or(\"/\") fallback on line 190 is unreachable since the else branch is only taken when parent_path.is_some(). Consider using unwrap() instead to make the code's intent clearer, or restructure the logic to avoid the unnecessary fallback.
| parent_path.unwrap_or("/"), | |
| parent_path.unwrap(), |
3402b14 to
0129763
Compare
Signed-off-by: longjin <longjin@DragonOS.org>
-修复 VFS 中相对路径与 dirfd 的解析逻辑,确保 parent inode 选取正确
-增强路径名检查,处理空路径/特殊名等异常情况
-添加针对 unlink 的测试用例
Note
Fixes parent inode resolution for dirfd-relative paths in openat/unlinkat, adds stricter path/dir checks and unlink behavior, and enables unlink tests.
vcore::resolve_parent_inodeand use it inopen.rs::do_sys_openat2(onO_CREAT) andvcore.rs::{do_remove_dir, do_unlink_at}to correctly resolve parents for dirfd-relative paths.do_remove_dir: reject/(EBUSY), empty path (ENOENT); ensure parent and target are dirs.do_unlink_at: reject empty path (ENOENT), trailing/(ENOTDIR); check parent is dir; do not follow final symlink; return EISDIR for directories; truncate page cache beforeunlink.unlink_testingvisor/whitelist.txtand add blocklisted cases inblocklists/unlink_test(pending fchmod).Written by Cursor Bugbot for commit 6592e11. This will update automatically on new commits. Configure here.