jingfei195887 opened a new pull request, #22458: URL: https://github.com/apache/nuttx/pull/22458
## Summary `lseek(fd, -3, SEEK_SET)` on TMPFS stores -3 in the open file position and returns errno 3 instead of EINVAL. Relative seeks can also overflow `off_t`. A failed pread/pwrite seek then leaves the descriptor at an invalid position. Validate the offset before adding it or updating `f_pos`. Return EINVAL for negative results and EOVERFLOW for unrepresentable results. Hold the existing file mutex while reading the seek base and updating the position. ## Impact - Functionality: fixes TMPFS seek error handling; valid backward seeks and seeks past EOF remain supported. - Compatibility: failed seeks preserve the current position and report the documented errno. No public API or configuration changes. - Build, hardware and documentation: no changes. - Safety: prevents invalid seek requests from installing a negative file position. This does not make the full pread/pwrite sequence atomic. ## Testing I confirm that changes are verified on local setup and work as intended: - Host: Linux x86_64, GCC 13.1.0. - Runtime target: sim:nsh, assertions enabled; CONFIG_FS_LARGEFILE=n and y (32-bit and 64-bit off_t). Same configuration and test source for each baseline/branch pair. - The local regression checks SEEK_SET/CUR/END, invalid whence, OFF_MIN/OFF_MAX, overflow, position preservation, pread/pwrite failures, successful backward and past-EOF seeks, file contents, hole zero filling, and cleanup. Testing logs before change (`a63275cdce8`): ```text TMPFSSEEK RESULT checks=95 failures=22 off_bits=32 TMPFSSEEK RESULT checks=95 failures=22 off_bits=64 ``` Testing logs after change (`3325971da68`): ```text TMPFSSEEK RESULT checks=95 failures=0 off_bits=32 TMPFSSEEK RESULT checks=95 failures=0 off_bits=64 ``` The simulator startup reports an existing duplicate /tmp mount failure. The test mounts its own /seekcheck TMPFS and checks that mount succeeds. Additional validation: qemu-armv7r:pnsh with 32-bit off_t and qemu-armv8a:knsh with 64-bit off_t build successfully. Full changed-file and commit checkpatch pass. Final Make/CMake builds pass with no warnings in the changed file; OSTest exits with status 0 and the tested-HEAD gate passes. Functional runs use apps a1b03f8926; the final gate uses apps 6ec742d050, including its updated OSTest suspend synchronization. No hardware runtime, protected/kernel runtime, SMP stress, or allocation-failure injection was performed. ## PR verification Self-Check - [x] This PR introduces only one functional change. - [x] I have updated all required description fields above. - [x] Commit title, sign-off and coding-style checks pass. - [ ] My PR is still work in progress (not ready for review). - [x] My PR is ready for review and can be safely merged into a codebase. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
