Repository navigation
fs/vfs: validate iovcnt bounds and iov_len overflow in readv/writev - #21544
Merged
michallenc merged 1 commit intoNov 9, 2026
Merged
Conversation
Swatantra-66
requested review from
Donny9,
anchao,
jerpelea,
xiaoxiang781216 and
yamt
as code owners
November 7, 2026 22:13
|
Add POSIX-mandated validation to file_readv() and file_writev(): 1. Reject iovcnt <= 0 or iovcnt > IOV_MAX with -EINVAL. 2. Validate total iov_len does not overflow SSIZE_MAX with -EINVAL. 3. Validate non-NULL iov_base for non-zero iov_len entries with -EFAULT (read path preserves kernel build exception for CONFIG_ARCH_TEXT_VBASE == 0). 4. Move per-entry overflow and NULL checks from compat loops to upfront validation in the main functions. Update include/sys/uio.h doc comments to remove "(Not implemented)" annotations and fix readv/writev copy-paste typo. Reference: POSIX.1-2017 (IEEE Std 1003.1-2017) readv/writev [EINVAL]. Assisted-by: Google Gemini:gemini-3.8-flash Signed-off-by: Swatantra Yadav <[email protected]>
Swatantra-66
force-pushed
the
fix/vfs-readv-writev-posix-validation
branch
from
November 8, 2026 05:59
7b7ba58 to
fa50eff
Compare
xiaoxiang781216
approved these changes
Nov 8, 2026
Contributor
Author
|
@xiaoxiang781216 Could you please re-run the failed 'arm-other' job? |
michallenc
approved these changes
Nov 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add POSIX-mandated
[EINVAL]validation tofile_readv()andfile_writev()foriovcntbounds andiov_lenoverflow, as required by POSIX.1-2017 (IEEE Std 1003.1-2017).Closes #21543
Problem
readv()andwritev()infs/vfs/fs_read.candfs/vfs/fs_write.cdid not validate:iovcnt <= 0oriovcnt > IOV_MAX(should return-EINVAL)iov_lenoverflowingSSIZE_MAX(should return-EINVAL)iov_basewith non-zeroiov_len(should return-EFAULT)The
iovcnt == 0case silently returned0, and the overflow check was only done mid-loop in the compat path.Changes
fs/vfs/fs_read.ciovcntbounds check,SSIZE_MAXoverflow loop, and NULLiov_basevalidation infile_readv(). Remove redundant mid-loop checks fromfile_readv_compat().fs/vfs/fs_write.cfile_writev()andfile_writev_compat().include/sys/uio.h(Not implemented)annotations fromEINVALdocs. Fixreadv()→writev()copy-paste typo. Remove stale TODO comment.Behavior Comparison
iovcnt == 00-EINVAL-EINVALiovcnt < 0-EINVAL-EINVALiovcnt > IOV_MAX-EINVAL-EINVALiov_len>SSIZE_MAX-EINVALiov_basewithiov_len > 0-EFAULTImpact
file_read()andfile_write()(single-buffer) callfile_readv()/file_writev()withiovcnt = 1, which passes all new validation.CONFIG_ARCH_TEXT_VBASE == 0) for ELF loading at address 0.Testing
I confirm that changes are verified on local setup and works as intended:
Style Verification
Build Log
Runtime Verification Log