🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

[Bug 300234] Dup does not use the lowest available descriptor

#302
From: bugzilla-noreply
Date: Thu, 29 Oct 2026 08:45
58 lines
3993 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300234

            Bug ID: 300234
           Summary: Dup does not use the lowest available descriptor
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: ml@netfence.it

Created attachment 276671
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=276671&action=edit
Fix fdcopy

Man page dup(2) clearly states:
The new descriptor returned by the call is the lowest numbered descriptor
currently not in use by the process.

On 15 (and I believe also in main) this is not always true.

For the curious, I found this out because one of the pratical effect is that
Cyrus IMAP fails to start automatically at boot in a jail. See:
https://mail-archive.freebsd.org/cgi/getmsg.cgi?fetch=124562+0+archive/2026/freebsd-ports/20261026.freebsd-ports

The problem seems to arise in function fdcopy.
This was changed in 14 -> 15 in order to skip duplication in some more cases;
alas, when that happens, it produces an incoherent filedesc structure.
All other functions assume such a structure is correct and never check, so
there is no recovery from this situation. The skipped number is forever lost.

I'm attaching a patch that seeems to solve.
In a test VM now Cyrus starts properly again.
However I'm no kernel expert, so I don't dare put it in production unless
someone with more knowledge than me reviews it.

While at it, I came to this conclusion by adding some KASSERTs around that
tested the content of filedesc structures: these are not in the patch (mainly
because I'm quite sure the way I added them was not orthodox). Would it be
worth to add them?

-- 
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-300234-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 300234] Dup does not use the lowest available descriptor
Date: Thu, 29 Oct 2026 08:45:03 +0000
Organization: Newsgate at muc.de e.V.
Sender: owner-freebsd-bugs@FreeBSD.org
Approved: news-admin@muc.de
Distribution: world
Message-ID: <bug-300234-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="77687"; 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=1793263503;
	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=/R4sgblD7X9hT/vNZ3A/SJZed127gh/g/X8b5MxGrAA=;
	b=HV3DhG64l2Y5rwmrkj1M3y07gSWnAyMaSA5w3Ph8HLrdtaI6IEf9CjJF21S7NFrbaxrz8H
	1e6we986EUqjNjb4wxAw/P1Inux9BgYlYP5ZYzpSrf8Qn1gmrj3dlwsz0RnJ3rD7NjW6ZK
	v1uXNfp2allAFarJf1NHckVbNY43sQK5TieOK+VfCHHSLOHx4uRl7DmpRoH3P5z65vQQuM
	8NJUjH+7aekby0uy6Ltx8v+W41gXf/VQfS+TlcPkDRP7InP4VNYk80MrPUsP9woURi9nxh
	/88KVvXeA4QXWWtWxMuhC+saNyCzqtZF2T9LUkA0FwysFYyixI0Vkx576tWmzA==
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