[BUG] fs/vfs: missing POSIX iovcnt bounds and iov_len overflow validation in readv/writev
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- c
- Lĩnh vực
- operating-systems
Hướng nghiên cứu
Read fs/vfs/fs_read.c and fs/vfs/fs_write.c, especially file_readv_compat() and file_writev_compat(), then check the existing declarations and TODOs in include/sys/uio.h. The issue describes the invalid iovcnt and iov_len cases to review; done means both calls reject invalid requests upfront without transferring data and the header notes reflect the completed validation.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
POSIX.1-2017 (IEEE Std 1003.1-2017) and POSIX.1-2024 explicitly mandate for both readv() and writev():
"The
readv()/writev()function shall fail if:
[EINVAL]The sum of theiov_lenvalues in theiovarray overflowed anssize_t.
or
[EINVAL]Theiovcntargument was less than or equal to 0, or greater than{IOV_MAX}."
Currently, NuttX's VFS layer (fs/vfs/fs_read.c and fs/vfs/fs_write.c) does not enforce these boundaries, leading to non-compliant return values and partial I/O on overflow.
In fact, this omission is already noted in include/sys/uio.h (lines 107-108, 132-133, 149-150):
/* In include/sys/uio.h: */
* EINVAL.
* The sum of the iov_len values in the iov array overflowed an ssize_t
* or The 'iovcnt' argument was less than or equal to 0, or greater than
* IOV_MAX (Not implemented).
*
* TODO: If the sum of the iov_len values is greater than SSIZE_MAX, the
* operation will fail and no data will be transferred.
Steps to Reproduce
-
Call
readv(fd, iov, 0)orwritev(fd, iov, 0):- Expected (POSIX): Returns
-1,errno = EINVAL. - Actual (NuttX): Returns
0(indicates zero-byte success / EOF).
- Expected (POSIX): Returns
-
Call
readv(fd, iov, -1)orwritev(fd, iov, -1):- Expected (POSIX): Returns
-1,errno = EINVAL. - Actual (NuttX): Bypasses validation and returns
0.
- Expected (POSIX): Returns
-
Call
readv()orwritev()withiovcnt > IOV_MAX:- Expected (POSIX): Returns
-1,errno = EINVAL. - Actual (NuttX): Allowed and processed unchecked.
- Expected (POSIX): Returns
-
Call
readv()orwritev()whereiov[0].iov_len = 10andiov[1].iov_len = SSIZE_MAX:- Expected (POSIX): Returns
-1,errno = EINVALupfront, with no data read or written. - Actual (NuttX): In
file_readv_compat()andfile_writev_compat(), transfers 10 bytes oniov[0], detects overflow oniov[1], executesbreak, and returns10(partial transfer) rather than rejecting the invalid request upfront.
- Expected (POSIX): Returns
Behavior Comparison
| Scenario / Parameter | POSIX IEEE Std 1003.1 | Current NuttX VFS | Proposed Fix |
|---|---|---|---|
iovcnt == 0 |
Fail with [EINVAL] |
Returns 0 (Success) |
Fail with -EINVAL |
iovcnt < 0 |
Fail with [EINVAL] |
Returns 0 (Success) |
Fail with -EINVAL |
iovcnt > IOV_MAX |
Fail with [EINVAL] |
Unchecked / Allowed | Fail with -EINVAL |
Sum of iov_len > SSIZE_MAX (i == 0) |
Fail with [EINVAL] |
Fails with -EINVAL |
Fail upfront with -EINVAL |
Sum of iov_len > SSIZE_MAX (i > 0) |
Fail with [EINVAL], no data transferred |
Returns partial bytes (ntotal) |
Fail upfront with -EINVAL, no data transferred |
Proposed Solution
- In
file_readv()andfile_writev(), validateiovcntupfront:if (iovcnt <= 0 || iovcnt > IOV_MAX) { return -EINVAL; } - Validate in an upfront pass that the accumulated sum of
iov_lendoes not exceedSSIZE_MAXbefore initiating any file operations or acquiring locks, returning-EINVALon overflow. - Update the comments and
TODOitems ininclude/sys/uio.hto reflect the completed POSIX conformance.
I have a patch ready with 100% nxstyle and checkpatch compliance and would be glad to submit a PR if this is the desired approach.
On which OS does this issue occur?
[OS: Linux]
What is the version of your OS?
Ubuntu 22.04 LTS (all)
NuttX Version
master
Issue Architecture
[Arch: all]
Issue Area
[Area: Posix]
Host information
Host: Linux x86_64 / Ubuntu 22.04 (Architecture-independent VFS logic bug)
Target: All architectures (sim:nsh, arm, etc.)
Verification
- I have verified before submitting the report.
- Ngôn ngữ chính
- C
- Star
- 4.1k
- Fork
- 1.8k
- Merge trung bình
- 1 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 843
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/nuttx
-
Please rerun `pre-commit run -a`Đang mởArch: all Arch: arm Area: Build system OS: Linux Type: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
apache/nuttx#19435 · 8 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Type: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
apache/nuttx#17343 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Arch: all OS: Linux Type: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
apache/nuttx#16249 · 7 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Arch: simulator Arch: xtensa Area: Kernel OS: Mac Type: Bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
apache/nuttx#21499 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
flac's CMake config is brokenĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
msys2/MINGW-packages#33356 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
kmod-project/kmod#492 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
PecanProject/sipnet#435 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
SDL_GPU Vulkan: wrong screen orientation on OpenHarmony (preTransform set without pre-rotation)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
libsdl-org/SDL#16670 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100