Commit f6ea32d
committed
vfs: reject oversized iovcnt in sys_read/sys_write instead of panicking
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.1 parent 97463b2 commit f6ea32d
3 files changed
Lines changed: 59 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
253 | 263 | | |
254 | 264 | | |
255 | 265 | | |
| |||
289 | 299 | | |
290 | 300 | | |
291 | 301 | | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
292 | 306 | | |
293 | 307 | | |
294 | 308 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
0 commit comments