-
-
Notifications
You must be signed in to change notification settings - Fork 166
fix(syscall): 修复 unlink 系统调用 #1365
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: master
Are you sure you want to change the base?
fix(syscall): 修复 unlink 系统调用 #1365
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 fixes the test case UnlinkTest.BadNamePtr by improving user space access validation. The main change is refactoring the user space address validation mechanism.
- Renamed
verify_area()tocheck_area_in_user_space()to better indicate its purpose - Renamed
check_user_access_by_page_table()tois_user_accessable()for clarity - Updated
copy_from_user()to use proper page table validation instead of simple address range checking
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| kernel/src/syscall/user_access.rs | Core refactoring: replaced address range checking with page table validation and renamed helper functions |
| kernel/src/syscall/mod.rs | Updated socket syscall validation to use renamed function |
| kernel/src/process/syscall/sys_execve.rs | Updated execve parameter validation to use renamed function |
| kernel/src/process/syscall/sys_clone.rs | Updated clone syscall validation to use renamed function |
| kernel/src/process/fork.rs | Updated fork TLS validation to use renamed function |
| kernel/src/net/socket/endpoint.rs | Updated socket endpoint validation to use renamed function |
| kernel/src/mm/syscall/sys_munmap.rs | Updated munmap validation to use renamed function |
| kernel/src/mm/syscall/sys_msync.rs | Updated msync validation to use renamed function |
| kernel/src/mm/syscall/sys_mprotect.rs | Updated mprotect validation to use renamed function |
| kernel/src/mm/syscall/sys_mmap.rs | Updated mmap validation to use renamed function |
| kernel/src/mm/syscall/sys_mincore.rs | Updated mincore validation to use renamed function |
| kernel/src/mm/syscall/sys_madvise.rs | Updated madvise validation to use renamed function |
| kernel/src/mm/mod.rs | Renamed verify_area to check_area_in_user_space |
| kernel/src/libs/futex/syscall/sys_robust_futex.rs | Updated robust futex validation to use renamed function |
| kernel/src/libs/futex/syscall/sys_futex.rs | Updated futex validation to use renamed function |
| kernel/src/filesystem/vfs/syscall/sys_getdents.rs | Updated getdents validation to use renamed function |
| kernel/src/filesystem/vfs/syscall/sys_getcwd.rs | Updated getcwd validation to use renamed function |
| kernel/src/driver/disk/ahci/ahcidisk.rs | Updated AHCI disk buffer validation to use renamed function |
| kernel/src/arch/x86_64/process/syscall.rs | Updated arch_prctl validation to use renamed function |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
kernel/src/syscall/user_access.rs
Outdated
| /// Copy data from user space to kernel space | ||
| pub unsafe fn copy_from_user(dst: &mut [u8], src: VirtAddr) -> Result<usize, SystemError> { | ||
| verify_area(src, dst.len()).map_err(|_| SystemError::EFAULT)?; | ||
| // 这里使用的函数错误了, verify_area() 函数只简单的检查 `src` 是否存在于用户地址空间,而不检查 `src` 是否真的被分配给用户进程使用。 |
Copilot
AI
Nov 12, 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.
Corrected spacing in comment: '使用的函数错误了' should have proper punctuation. The comma should be a Chinese comma ','.
| // 这里使用的函数错误了, verify_area() 函数只简单的检查 `src` 是否存在于用户地址空间,而不检查 `src` 是否真的被分配给用户进程使用。 | |
| // 这里使用的函数错误了,verify_area() 函数只简单的检查 `src` 是否存在于用户地址空间,而不检查 `src` 是否真的被分配给用户进程使用。 |
kernel/src/syscall/user_access.rs
Outdated
| /// * `true` if all pages are mapped and have required permissions | ||
| /// * `false` if any page is not mapped or lacks required permissions | ||
| fn check_user_access_by_page_table(addr: VirtAddr, size: usize, check_write: bool) -> bool { | ||
| fn is_user_accessable(addr: VirtAddr, size: usize, check_write: bool) -> bool { |
Copilot
AI
Nov 12, 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.
Corrected spelling of 'accessable' to 'accessible'.
| fn is_user_accessable(addr: VirtAddr, size: usize, check_write: bool) -> bool { | |
| fn is_user_accessible(addr: VirtAddr, size: usize, check_write: bool) -> bool { |
kernel/src/mm/mod.rs
Outdated
| /// | ||
| /// 否则返回Ok(()) | ||
| pub fn verify_area(addr: VirtAddr, size: usize) -> Result<(), SystemError> { | ||
| pub fn check_area_in_user_space(addr: VirtAddr, size: usize) -> Result<(), SystemError> { |
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.
这里重命名的意义在于?这种广泛使用的命名不要更改。
f735b8b to
e5034d7
Compare
fslongjin
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.
这个pr看起来没有实质的更改?
这几天一堆 ddl ,这个 PR 要delay一下 (┬┬﹏┬┬) |
e5034d7 to
61284d4
Compare
问题描述
gVisor 的测试用例
UnlinkTest.BadNamePtr通过unlink(reinterpret_cast<char*>(1))模拟用户传入无效指针。DragonOS 预期返回EFAULT,但现状是内核不断陷入copy_from_user触发的缺页重试,最终将进程直接 kill,测试无法继续。排查过程
copy_from_user,复现地址形如0x1。verify_area()只验证指针是否落在用户空间地址范围,未校验该范围是否真的映射且具备访问权限。do_user_addr_fault中也看到由于缺少显式的 fail-fast,非法地址反复触发 fault handler,最终通过 SIGSEGV 结束进程。修复方案
docs(syscall/user_access):记录问题定位过程,明确“仅做边界检查”的现有行为。refactor(mm):将verify_area()重命名为check_area_in_user_space(),突出它只负责判定是否落在用户虚拟地址空间这一事实。fix:在copy_from_user()中引入新的映射校验,调用is_user_accessable()(检测页表映射 + 用户/写权限),对未映射或权限不足的区域立即返回-EFAULT,避免进入缺页处理循环。refactor(syscall/user_access):将原先名为check_user_access_by_page_table()的布尔函数重命名为is_user_accessable(),让调用语义更贴近布尔返回值。style:顺手整理了一处代码格式问题,保持文件一致性。TODO
copy_from_user()中新增页表级访问校验并返回-EFAULTis_user_accessable()的拼写修正为is_user_accessible()(待进一步提交)测试验证