TECH Signal 404
SCM_RIGHTS recvmsg() silently discards file descriptors when ancillary buffer is too small
Linux's SCM_RIGHTS implementation truncates and closes file descriptors that don't fit in the receiver's ancillary buffer, and message-boundary enforcement causes short reads that break edge-triggered I/O assumptions.
Engineers passing file descriptors over Unix domain sockets can silently lose descriptors if their recvmsg() ancillary buffer is undersized, with no recovery mechanism. The kernel's artificial message boundaries also mean short reads don't reliably indicate an empty buffer, breaking common edge-triggered I/O patterns.
Written by elseif from the cluster below · every claim links back to a sourceThe three things worth knowing
A single SCM_RIGHTS message can carry up to 253 file descriptors, but if recvmsg() lacks sufficient ancillary buffer space, excess descriptors are silently discarded and closed with no way to retrieve them later.
recvmsg() artificially limits reads to the byte range of the ancillary message, causing short reads even when more data is buffered, which breaks edge-triggered I/O assumptions that a short read means no more data.
Regular read() calls exhibit the same early termination behavior despite being unable to receive ancillary messages, making the root cause of fragmented reads non-obvious during debugging.
THE CLUSTER
↗