vfs: reject oversized iovcnt in sys_read/sys_write (fix app-triggerable kernel panic) - #1448
Open
gburd wants to merge 1 commit into
Open
vfs: reject oversized iovcnt in sys_read/sys_write (fix app-triggerable kernel panic)#1448gburd wants to merge 1 commit into
gburd wants to merge 1 commit into
Conversation
sys_read()/sys_write() summed iov_len over niov entries and only then asserted niov <= UIO_MAXIOV before a VLA copy. niov is caller-controlled and reaches here unvalidated from readv/writev/preadv/pwritev/preadv2/pwritev2, io_uring READV/WRITEV(_FIXED), and libaio PREADV/PWRITEV. Two problems: - OSv keeps assert() live in _KERNEL builds (include/api/assert.h), so niov > UIO_MAXIOV -> __assert_fail -> abort() = whole-VM panic. Any unprivileged app crashes the kernel with one readv(fd, iov, 0x40000000). (In a unikernel, an app-triggerable panic is a full-system DoS.) - The summation loop dereferences iov[i] for up to niov entries *before* the assert -> out-of-bounds read walk. - struct iovec copy_iov[niov] is a VLA sized by the unvalidated count. Reject niov > UIO_MAXIOV with EINVAL at function entry (before touching iov), which fixes all three and matches Linux's EINVAL for iovcnt out of range. Added tst-iovcnt-guard: readv/writev with a huge iovcnt now return -1/EINVAL instead of aborting.
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.
Security fix — local DoS (any unprivileged app can panic the kernel).
sys_read()/sys_write()(fs/vfs/vfs_syscalls.cc) summediov_lenovernioventries and only then didassert(niov <= UIO_MAXIOV)before astruct iovec copy_iov[niov]VLA.niovis caller-controlled and reaches here unvalidated fromreadv/writev/preadv/pwritev/preadv2/pwritev2, io_uringREADV/WRITEV(_FIXED), and libaioPREADV/PWRITEV.Three problems:
assert()live in_KERNELbuilds (include/api/assert.h:#if defined NDEBUG && !defined _KERNEL), soniov > UIO_MAXIOV→__assert_fail→abort()= whole-VM panic. In a unikernel an app-triggerable panic is a full-system DoS.iov[i]for up tonioventries before the assert → out-of-bounds read.copy_iov[niov]is a VLA sized by the unvalidated count (kernel-stack blowout).PoC
Also reachable by submitting an
IORING_OP_READVSQE withlen = 0x40000000.Fix
Reject
niov > UIO_MAXIOVwithEINVALat function entry (before touchingiov), matching Linux'sEINVALfor an out-of-rangeiovcnt. Fixes all three issues.Severity
High (CVSS ~7.1, AV:L/AC:L/PR:L/UI:N/A:H) — trivially reachable kernel panic.
Verified with
tst-iovcnt-guard(new):readv/writevwith a hugeiovcntnow return-1/EINVALinstead of aborting.