Review report

core: PR #36688

1 suggestion

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Optional improvements

Link

[suggestion] · An urgent pointer ahead of received data can still spin the macOS/BSD net thread

A peer that crafts TCP segments can keep the macOS/BSD select-based loop waking without readable data; this pre-existing behavior is harder to trigger than before, and its impact is uncertain.

Location: src/netbase.cpp:573 (head).

Details and suggested fix

On non-Linux builds, Sock::WaitMany uses select() and places sockets waiting to receive in the exception set. An exception hit becomes ErrorEvent, so SocketHandlerConnected calls Recv(). This change enables SO_OOBINLINE, which clears the urgent mark once the urgent byte arrives and is read inline. But on FreeBSD and XNU, exception readiness follows the receive-side urgent mark, which tcp_input sets from the segment's urgent pointer whether or not SO_OOBINLINE is enabled. The option only keeps the urgent byte in the normal stream.

TCP permits the urgent pointer to reach up to 64 KiB beyond the data in a segment. A peer using crafted segments, for example through a raw socket or userspace TCP stack, can send a small payload with the pointer ahead and withhold the intervening bytes, or keep advancing the pointer. select() can then keep reporting an exception while Recv() returns WSAEWOULDBLOCK. The peer remains connected, and the net thread loops without its 50 ms wait while this continues. Other peers are still serviced, but the loop consumes CPU and adds lock traffic. This is not a regression: before this change, a plain MSG_OOB byte could cause the same loop. The behavior is based on FreeBSD/XNU source and has not been confirmed on a running macOS or FreeBSD host; whether the CPU and lock overhead materially degrades a node remains open.

Restrict adding sockets to the exception set to WIN32 to avoid this case. The cited rationale in #36665 is detecting failed connects on Windows, which does not report OOB data in exceptfds once SO_OOBINLINE is set. On POSIX, ConnectToSocket already detects failed connects through readiness plus SO_ERROR. If this is left to a follow-up, narrow the new comment so it does not imply that select() stops reporting urgent state.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.