🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: muc.lists.freebsd.bugs
Article #329

[Bug 300446] sendmsg with data and SCM_RIGHTS incorrectly queues and delivers file descriptors on failure (EAGAIN) when the peer...

#329
From: bugzilla-noreply
Date: Mon, 02 Nov 2026 14:25
100 lines
5143 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300446

            Bug ID: 300446
           Summary: sendmsg with data and SCM_RIGHTS incorrectly queues
                    and delivers file descriptors on failure (EAGAIN) when
                    the peer's buffer free space exactly matches the
                    control message size
           Product: Base System
           Version: 15.1-STABLE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: alejo@murena.io
 Attachment #276916 text/plain
         mime type:

Created attachment 276916
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=276916&action=edit
minimal reproducible example

Overview: 

On an AF_UNIX stream or seqpacket socket, when the peer's receive buffer has
free space exactly equal to the size of the internalized control message,
sendmsg with data and SCM_RIGHTS queues the control message, sends no data, and
fails with EAGAIN/EWOULDBLOCK. Although the system call fails, the file
descriptor incorrectly reaches the peer. Under SA_RESTART, the kernel
automatically restarts the call, leading to duplicate delivery of the
descriptor.


Steps to Reproduce: 

Due to the quite specific case, it's almost impossible to run into the bug in
real life. So I prepared a special test (scm_rights_eagain.c in the
attachment). Compile and execute it on a FreeBSD host where the receiver leaves
24 bytes free in its buffer:
`cc scm_rights_eagain.c`
and run
`./scm_rights_eagain`

Observe the output across the three execution modes: no retry, explicit retry,
and SA_RESTART.


Actual Results: 

No retry: sendmsg returns -1 (Resource temporarily unavailable); recvmsg gets 0
bytes and 1 fd.
Retry: sendmsg returns -1 (Resource temporarily unavailable), followed by a
successful retry (sendmsg 2), and recvmsg gets 2 bytes and 2 fds.
SA_RESTART: sendmsg returns 2 (ok), and recvmsg gets 2 bytes and 2 fds
(duplicate descriptor delivery).


Expected Results: 

A failed sendmsg call should be atomic and leave no side effects; descriptors
should not be delivered to the peer if the system call fails or returns an
error. The same way as if only 23 bytes were free.


Build Date & Hardware: 

Version: 15.1-RELEASE-p4 (releng/15.1-n283627-e38a7085f3a8 GENERIC)


Additional Builds and Platforms: 

Introduced via commit d15792780760 (unix: new implementation of unix/stream &
unix/seqpacket).
releng/14.3 does not contain this implementation and is unaffected.


Additional Information: 

While it's unclear if this bug can be exploited, it remains a correctness
question.
Code Reference: sys/kern/uipc_usrreq.c, uipc_sosend_stream_or_seqpacket()

-- 
You are receiving this mail because:
You are the assignee for the bug.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID: <bug-300446-227@https.bugs.freebsd.org/bugzilla/>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: bugzilla-noreply@freebsd.org
Newsgroups: muc.lists.freebsd.bugs
Subject: [Bug 300446] sendmsg with data and SCM_RIGHTS incorrectly queues and
 delivers file descriptors on failure (EAGAIN) when the peer's buffer free
 space exactly matches the control message size
Date: Mon, 02 Nov 2026 14:25:55 +0000
Organization: Newsgate at muc.de e.V.
Sender: owner-freebsd-bugs@FreeBSD.org
Approved: news-admin@muc.de
Distribution: world
Message-ID: <bug-300446-227@https.bugs.freebsd.org/bugzilla/>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2";
	logging-data="87173"; mail-complaints-to="news-admin@muc.de"
X-Original-To: bugs@mlmmj.nyi.freebsd.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1793629555;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=gRICOKhMlPFC7z71ZNWRRToGPYCri48JHKhWURFc0iQ=;
	b=pW+TSaxYwGO3mj7jdkLlnRBIF4P1FinDj4uEmfPg149bWTio0B0+DYbXdAYhtzpq0E3hdb
	LKmU5EqT91FzH6jSkovpyjDhNJkacI6nPeTJPsr+nx27dyoZHRGuSY2VI4A8D40z1A1rbH
	aF//t0flP2ABmnx9lMGeyL/yNzLGXbAScLMZkwHhl24DnajiOvVhvMnYg4b/Lqklh/vmEz
	D6xMpAZ3wwnmJzABa/pAYkaj/6zQ5y3AC+vv4pO5Q97PPcFYWSJp3FK8Mm16REjoOwVC1I
	0ZMFGRFPnrjTJgHL8mIeO3pRN6ZGtpMlnimpY8MZBALfnSl/PLlSRQxwe1NVQw==
X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f
Auto-Submitted: auto-generated
Precedence: list
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes