fix(vfs):调整 lseek 行为 —— 禁止 procfs SEEK_END,目录 SEEK_END 返回 MAX_LFS_FILESIZE#1344
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for the lseek syscall test from gvisor, with implementation improvements to handle edge cases for procfs files and directories.
- Added
lseek_testto the gvisor test whitelist with a corresponding blocklist for unsupported test cases - Enhanced
lseekimplementation to handle procfs files and directories correctly - Fixed error code from
EOVERFLOWtoEINVALfor negative seek positions - Removed extraneous blank lines in syscall handler code
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| user/apps/tests/syscall/gvisor/whitelist.txt | Enabled lseek_test in the test suite |
| user/apps/tests/syscall/gvisor/blocklists/lseek_test | Created blocklist for 3 unsupported lseek test cases |
| kernel/src/filesystem/vfs/syscall/sys_lseek.rs | Removed unnecessary blank lines for code cleanup |
| kernel/src/filesystem/vfs/file.rs | Added procfs and directory-specific lseek handling, fixed error code for negative positions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
kernel/src/filesystem/vfs/file.rs
Outdated
| crate::driver::base::block::SeekFrom::SeekEnd(_) => { | ||
| return Err(SystemError::EINVAL); | ||
| } | ||
| crate::driver::base::block::SeekFrom::Invalid => { |
There was a problem hiding this comment.
Use the imported SeekFrom type directly instead of the fully qualified path crate::driver::base::block::SeekFrom. The type is already imported at line 11, so you can simplify to SeekFrom::SeekEnd(_) and SeekFrom::Invalid.
| crate::driver::base::block::SeekFrom::SeekEnd(_) => { | |
| return Err(SystemError::EINVAL); | |
| } | |
| crate::driver::base::block::SeekFrom::Invalid => { | |
| SeekFrom::SeekEnd(_) => { | |
| return Err(SystemError::EINVAL); | |
| } | |
| SeekFrom::Invalid => { |
kernel/src/filesystem/vfs/file.rs
Outdated
| if FileType::Dir == file_type { | ||
| // 对目录,返回 Linux 常见语义:允许 SEEK_END 并返回 MAX_LFS_FILESIZE。 | ||
| // 测试接受 MAX_LFS_FILESIZE 或 EINVAL,但为通过当前测试选择返回 MAX_LFS_FILESIZE。 | ||
| const MAX_LFS_FILESIZE: i64 = 0x7fffffffffffffff; |
There was a problem hiding this comment.
The magic number 0x7fffffffffffffff should use a more explicit representation. Consider using i64::MAX instead of the hex literal for better readability and maintainability.
| const MAX_LFS_FILESIZE: i64 = 0x7fffffffffffffff; | |
| const MAX_LFS_FILESIZE: i64 = i64::MAX; |
| match origin { | ||
| SeekFrom::SeekEnd(_) => { | ||
| return Err(SystemError::EINVAL); | ||
| } | ||
| SeekFrom::Invalid => { | ||
| return Err(SystemError::EINVAL); | ||
| } | ||
| _ => {} |
There was a problem hiding this comment.
SeekFrom::SeekEnd(_) | SeekFrom::Invalid
可以这样合并测试条件。不然太啰嗦了
kernel/src/filesystem/vfs/file.rs
Outdated
| if FileType::Dir == file_type { | ||
| // 对目录,返回 Linux 常见语义:允许 SEEK_END 并返回 MAX_LFS_FILESIZE。 | ||
| // 测试接受 MAX_LFS_FILESIZE 或 EINVAL,但为通过当前测试选择返回 MAX_LFS_FILESIZE。 | ||
| const MAX_LFS_FILESIZE: i64 = i64::MAX; |
|
还有,需要修改pr标题 |
vfs: 调整 lseek 行为 —— 禁止 procfs SEEK_END,目录 SEEK_END 返回 MAX_LFS_FILESIZE
注意:
Note
Refines
lseekto reject procfsSEEK_END, returnMAX_LFS_FILESIZEfor directorySEEK_END, treat negative results asEINVAL, and enables gVisorlseek_testwith targeted blocklists.kernel/src/filesystem/vfs/file.rs):SEEK_ENDandInvalidinlseek, returnEINVAL.SEEK_ENDreturnsMAX_LFS_FILESIZE.EINVAL.lseek_testinuser/apps/tests/syscall/gvisor/whitelist.txt.user/apps/tests/syscall/gvisor/blocklists/lseek_test:LseekTest.ProcStatTwice,LseekTest.EtcPasswdDup,LseekTest.SeekDataAndSeekHole.Written by Cursor Bugbot for commit f3374a0. This will update automatically on new commits. Configure here.