Swatantra-66 opened a new pull request, #21544: URL: https://github.com/apache/nuttx/pull/21544
**Summary** Add POSIX-mandated `[EINVAL]` validation to `file_readv()` and `file_writev()` for `iovcnt` bounds and `iov_len` overflow, as required by POSIX.1-2017 (IEEE Std 1003.1-2017). Closes #21543 **Problem** `readv()` and `writev()` in `fs/vfs/fs_read.c` and `fs/vfs/fs_write.c` did not validate: - `iovcnt <= 0` or `iovcnt > IOV_MAX` (should return `-EINVAL`) - Sum of `iov_len` overflowing `SSIZE_MAX` (should return `-EINVAL`) - NULL `iov_base` with non-zero `iov_len` (should return `-EFAULT`) The `iovcnt == 0` case silently returned `0`, and the overflow check was only done mid-loop in the compat path. **Changes** | File | Change | |------|--------| | `fs/vfs/fs_read.c` | Add upfront `iovcnt` bounds check, `SSIZE_MAX` overflow loop, and NULL `iov_base` validation in `file_readv()`. Remove redundant mid-loop checks from `file_readv_compat()`. | | `fs/vfs/fs_write.c` | Same pattern for `file_writev()` and `file_writev_compat()`. | | `include/sys/uio.h` | Remove `(Not implemented)` annotations from `EINVAL` docs. Fix `readv()` → `writev()` copy-paste typo. Remove stale TODO comment. | **Behavior Comparison** | Condition | Before | After | POSIX Requirement | |-----------|--------|-------|-------------------| | `iovcnt == 0` | Returns `0` | Returns `-EINVAL` | `-EINVAL` | | `iovcnt < 0` | Undefined | Returns `-EINVAL` | `-EINVAL` | | `iovcnt > IOV_MAX` | No check | Returns `-EINVAL` | `-EINVAL` | | Sum of `iov_len` > `SSIZE_MAX` | Checked only in compat loop (read) | Upfront check in both paths | `-EINVAL` | | NULL `iov_base` with `iov_len > 0` | Checked only in write compat loop | Upfront check in both read and write | `-EFAULT` | **Impact** - `file_read()` and `file_write()` (single-buffer) call `file_readv()`/`file_writev()` with `iovcnt = 1`, which passes all new validation. - The read-path NULL check preserves the existing kernel build exception (`CONFIG_ARCH_TEXT_VBASE == 0`) for ELF loading at address 0. - No behavioral change for valid inputs. **Testing** Build verification: ``` Host: Ubuntu (WSL2) NuttX Version: master (commit 7b7ba58d72) Configuration: sim:nsh ``` ``` $ tools/configure.sh sim:nsh $ make -j$(nproc) ``` Style check: `nxstyle` clean on all modified files. No lines exceed 78 characters. No trailing whitespace. -- 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]
