Repository navigation
net/local: fix integer overflow in sendpacket and SCM leak in sendmsg - #21492
Merged
xiaoxiang781216 merged 1 commit intoNov 6, 2026
Merged
Conversation
1. In local_send_preamble(), packet length was accumulated into lc_size_t pktlen (uint16_t when CONFIG_DEV_PIPE_MAXSIZE <= 65535). If the sum of iov_len values exceeded 65535, pktlen silently wrapped around before checking against rcvsize, allowing oversized datagrams to corrupt FIFO packet framing. Accumulate total into size_t and validate against payload space before adding. 2. In local_send_packet(), sendlen was typed lc_size_t. Stream socket writes (SOCK_STREAM) larger than 64 KB wrapped around modulo 65536. Change sendlen and function return type to ssize_t, and handle zero iovec count by returning 0. 3. In local_sendmsg(), the return value of local_sendto() / local_send() was assigned to size_t len, making if (len < 0 && count > 0) dead code and leaking SCM file descriptors on error. Use ssize_t ret. 4. In local_sendmsg(), reject stream socket sends (SOCK_STREAM) with control messages (SCM_RIGHTS) when total payload length is zero with -EINVAL (matching Linux unix(7)) to avoid queuing orphaned descriptors when no data is written to wake up the receiver. Signed-off-by: Swatantra Yadav <[email protected]> Assisted-by: Google Gemini
Swatantra-66
requested review from
GUIDINGLI,
jerpelea and
xiaoxiang781216
as code owners
November 5, 2026 12:20
acassis
approved these changes
Nov 5, 2026
|
michallenc
approved these changes
Nov 5, 2026
xiaoxiang781216
approved these changes
Nov 5, 2026
casaroli
requested changes
Nov 6, 2026
This was referenced Nov 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two integer overflow bugs and two SCM (Socket Control Message) descriptor handling bugs in Unix domain sockets (
net/local):Datagram preamble integer wrap-around (
local_send_preamble):pktlenwas accumulated intolc_size_t(uint16_twhenCONFIG_DEV_PIPE_MAXSIZE <= 65535). If the sum ofiov_lenvalues exceeded 65535,pktlensilently wrapped around modulo 65536 before checking againstrcvsize, allowing oversized datagrams to pass validation, write a truncated packet length header, and corrupt FIFO packet framing. Now accumulates the total insize_tand validates payload headroom before adding each buffer.Stream send 16-bit truncation (
local_send_packet):sendlenwas typedlc_size_t(uint16_t). Stream socket writes (SOCK_STREAM) larger than 64 KB wrapped around modulo 65536, returning a bogus truncated byte count to userspace. Changedsendlenand function return types tossize_t.Zero-length send handling (
local_send_packet):Explicitly returns
0whenlen == 0so empty datagrams (e.g. heartbeat/ping) succeed and return 0 bytes instead of falling through to-EINVAL.Dead error cleanup & descriptor leak (
local_sendmsg):The return value of
local_sendto()/local_send()was assigned to unsignedsize_t len, renderingif (len < 0 && count > 0)dead code. Any send failure leaked the control message file descriptors. Changed to signedssize_t ret.Orphaned SCM descriptors on zero-payload stream sends (
local_sendmsg):On stream sockets (
SOCK_STREAM), sendingSCM_RIGHTSwith 0 bytes of payload queued descriptors, but wrote 0 bytes to the stream FIFO. The receiver never woke up, leaving descriptors permanently orphaned inlc_cfpsuntillc_cfpcountreachedLOCAL_NCONTROLFDS(4) and broke future sends with-EMFILE. Now rejects zero-data stream SCM sends with-EINVAL, strictly conforming to POSIX / Linuxunix(7)behavior (if (scm && !total_len) return -EINVAL;).Impact
Testing
./tools/checkpatch.sh -u -f net/local/local_sendpacket.c net/local/local_sendmsg.c net/local/local.h(exit code 0, all checks passed).