Skip to content

net/usrsock: fail sendmsg when the sum of iov_len overflows - #21434

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Swatantra-66:fix/usrsock-sendmsg-overflow
Nov 5, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
Swatantra-66:fix/usrsock-sendmsg-overflow

Conversation

@Swatantra-66

@Swatantra-66 Swatantra-66 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fails sendmsg() in net/usrsock with -EINVAL when the sum of iov_len values exceeds MIN(SSIZE_MAX, UINT32_MAX).

Previously, usrsock_sendmsg() accumulated iov_len values directly into req.buflen (uint32_t) without overflow detection. If the sum wrapped around, the subsequent check:

if (req.buflen > UINT32_MAX)
  {
    req.buflen = UINT32_MAX;
  }

was dead code because req.buflen is typed uint32_t and can never exceed UINT32_MAX. This allowed silent integer wrap-around and protocol desync when queuing large scatter/gather vectors.

The check enforces (size_t)MIN(SSIZE_MAX, UINT32_MAX) - req.buflen:

  • On 32-bit platforms, it enforces the POSIX IEEE Std 1003.1 limit (SSIZE_MAX = 2 GB), matching net/inet (commit 3671f94) and fs/vfs/fs_uio.c.
  • On 64-bit platforms, SSIZE_MAX is 8 Exabytes, so the bound clamps to UINT32_MAX (4 GB) to prevent req.buflen (uint32_t) from silently wrapping around.

Impact

  • Impact on user: POSIX IEEE Std 1003.1 compliance for sendmsg() over usrsock. Prevents silent integer wrap-around and protocol corruption when the sum of iov_len values exceeds SSIZE_MAX or UINT32_MAX.
  • Impact on build: None.
  • Impact on hardware: None.

Testing

  • CI Linters: Verified locally against full CI checkpatch: ./tools/checkpatch.sh -c -u -m -g upstream/master..HEAD (exit code 0, all checks passed including codespell, cvt2utf, commit message validator, and nxstyle).
  • nxstyle: Verified net/usrsock/usrsock_sendmsg.c has 0 errors and 0 warnings with nxstyle.
  • Sign-compare: Verified clean compilation under GCC with -Werror=sign-compare on both 32-bit and 64-bit targets.

@github-actions github-actions Bot added Area: Networking Effects networking subsystem Size: S The size of the change in this PR is small labels Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

Comment thread net/usrsock/usrsock_sendmsg.c Resolved
@Swatantra-66
Swatantra-66 force-pushed the fix/usrsock-sendmsg-overflow branch from 689bb41 to f0ce5d1 Compare November 4, 2026 11:43
jerpelea
jerpelea previously approved these changes Nov 4, 2026
xiaoxiang781216
xiaoxiang781216 previously approved these changes Nov 4, 2026
Comment thread net/usrsock/usrsock_sendmsg.c Resolved
Comment thread net/usrsock/usrsock_sendmsg.c Resolved
With more than one iovec, usrsock_sendmsg() adds the iov_len values
into req.buflen. If the sum overflows, it silently wraps around, and
the subsequent check (req.buflen > UINT32_MAX) was dead code because
req.buflen is a uint32_t.

Fail with -EINVAL when the sum of iov_len values exceeds
MIN(SSIZE_MAX, UINT32_MAX). This enforces the POSIX IEEE Std 1003.1
limit (SSIZE_MAX) on 32-bit platforms and prevents 32-bit wrap-around
of req.buflen (UINT32_MAX) on 64-bit platforms.

Signed-off-by: Swatantra Yadav <maverickswatantra@gmail.com>
Assisted-by: Google Gemini
@Swatantra-66
Swatantra-66 force-pushed the fix/usrsock-sendmsg-overflow branch from 5e12061 to ea46d80 Compare November 4, 2026 15:54
@xiaoxiang781216
xiaoxiang781216 merged commit 6e1126a into apache:master Nov 5, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Networking Effects networking subsystem Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants