Skip to content

virtio/net/unixgram: Fix SO_SNDBUF size on macOS#574

Merged
slp merged 2 commits intocontainers:mainfrom
nirs:macos-send-buffer-size
Mar 12, 2026
Merged

virtio/net/unixgram: Fix SO_SNDBUF size on macOS#574
slp merged 2 commits intocontainers:mainfrom
nirs:macos-send-buffer-size

Conversation

@nirs
Copy link
Contributor

@nirs nirs commented Mar 10, 2026

On macOS, Unix datagram sockets do not use the send buffer for queuing. The send buffer size determines the maximum datagram size that can be sent. Set SO_SNDBUF to the maximum frame size (65550) instead of 7 MiB to match the actual semantics.

On Linux, keep the 7 MiB send buffer for actual queuing.

Also fix the SO_RCVBUF warning message which incorrectly said "SO_SNDBUF".

@slp
Copy link
Collaborator

slp commented Mar 10, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly adjusts the SO_SNDBUF size for macOS Unix datagram sockets and fixes an incorrect log message for SO_RCVBUF. The changes are logical and improve platform-specific behavior. I've included one suggestion to refactor the new constants for better maintainability by avoiding a repeated magic number.

@nirs nirs force-pushed the macos-send-buffer-size branch from cdd5de7 to fe010e7 Compare March 10, 2026 15:42
mem::size_of is a const fn, so the virtio-net header length can be a
compile-time constant instead of a function call. This allows using it
in const expressions, which is needed in a following change to derive
the macOS socket send buffer size from MAX_BUFFER_SIZE.

Assisted-by: Cursor/Claude Opus 4.6
Signed-off-by: Nir Soffer <nirsof@gmail.com>
@nirs nirs force-pushed the macos-send-buffer-size branch from fe010e7 to e927043 Compare March 10, 2026 16:20
@nirs
Copy link
Contributor Author

nirs commented Mar 10, 2026

Latest version defines the maximum frame size using existing constants instead of adding another magic number.

/gemini review

@nirs nirs force-pushed the macos-send-buffer-size branch from e927043 to d794ebe Compare March 10, 2026 16:26
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly fixes the SO_SNDBUF size for Unix datagram sockets on macOS, aligning it with the kernel's semantics for maximum datagram size, and refactors a function into a constant for the virtio net header length. While these changes improve correctness and code quality, a potential Guest-to-Host Denial of Service (DoS) vulnerability has been identified in the NetWorker::process_tx loop. The code currently lacks validation to ensure that the total length of a packet received from the guest is at least as large as the virtio-net header size. Sending a shorter packet could cause the host's worker thread to panic. Additionally, a copy-paste error in a log message for SO_RCVBUF has been fixed. Please address the DoS vulnerability by adding packet length validation before processing.

On macOS, Unix datagram sockets do not use the send buffer for
queuing. The send buffer size determines the maximum datagram size
that can be sent. Set SO_SNDBUF to the maximum frame size (65550)
instead of 7 MiB to match the actual semantics.

On Linux, keep the 7 MiB send buffer for actual queuing.

Also fix the SO_RCVBUF warning message which incorrectly said
"SO_SNDBUF".

Assisted-by: Cursor/Claude Opus 4.6
Signed-off-by: Nir Soffer <nirsof@gmail.com>
@nirs nirs force-pushed the macos-send-buffer-size branch from d794ebe to 4a90cfe Compare March 11, 2026 18:17
@nirs nirs requested a review from slp March 11, 2026 18:18
Copy link
Collaborator

@slp slp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@slp slp merged commit b7a2837 into containers:main Mar 12, 2026
11 checks passed
@nirs nirs deleted the macos-send-buffer-size branch March 12, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants