🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

[Bug 300091] [sctp] SO_SETFIB setsockopt() silently fails on SCTP sockets

#260
From: bugzilla-noreply
Date: Mon, 26 Oct 2026 13:18
121 lines
5770 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300091

            Bug ID: 300091
           Summary: [sctp] SO_SETFIB setsockopt() silently fails on SCTP
                    sockets
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: albin.hellqvist@ericsson.com

Description:

Commit caccbaef8e26 ("socket: Move SO_SETFIB handling to protocol layers", Feb
6, 2025) moved SO_SETFIB handling from the generic socket layer in sosetopt()
into each protocol's pr_ctloutput(). The TCP/IPv4, IPv6, raw IP, raw IPv6, and
route socket handlers were all updated to call sooptcopyin() and sosetfib().
However, the SCTP handler in sctp_ctloutput() (sys/netinet/sctp_usrreq.c) was
not updated.

The SCTP handler (originally added in commit d089f9b9155f) still does:

inp->fibnum = so->so_fibnum;

This worked before because the generic socket layer set so->so_fibnum first.
After caccbaef8e26, the generic layer no longer does this, it delegates
entirely to pr_ctloutput. So so->so_fibnum is never updated and the
user-provided FIB value is never read from the sockopt buffer.

The result is that setsockopt(fd, SOL_SOCKET, SO_SETFIB, &fibnum,
sizeof(fibnum)) on an SCTP socket returns 0 (success) but does nothing, the FIB
stays at its previous value.

For comparison, the correct implementation in ip_ctloutput()
(sys/netinet/ip_output.c):

case SO_SETFIB:
    error = sooptcopyin(sopt, &optval, sizeof(optval), sizeof(optval));
    if (error != 0)
        break;
    INP_WLOCK(inp);
    error = sosetfib(inp->inp_socket, optval);
    if (error == 0)
        inp->inp_inc.inc_fibnum = optval;
    INP_WUNLOCK(inp);
    break;

Affected versions:
- main (15-CURRENT) since commit caccbaef8e26 (Feb 6, 2025)
- stable/14 since MFC a55bde2328e5, affects 14.3, 14.4, 14.5
- releng/15.0, releng/15.1

Not affected:
- FreeBSD 13.x (generic socket layer still handles SO_SETFIB)
- FreeBSD 14.0, 14.1, 14.2

How to reproduce:

int fd  = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP);
int fib = 1;

// Returns 0 (success) but FIB stays at 0:
setsockopt(fd, SOL_SOCKET, SO_SETFIB, &fib, sizeof(fib));

Verified by checking that SCTP source address selection
(sctp_source_address_selection) returns EHOSTUNREACH when the socket's FIB
doesn't match the routing table where addresses are configured.

Proposed fix:

The SCTP handler needs to call sooptcopyin() to read the value from userspace
and sosetfib() to update so->so_fibnum, matching the pattern used by
ip_ctloutput() and ip6_ctloutput():

--- a/sys/netinet/sctp_usrreq.c
+++ b/sys/netinet/sctp_usrreq.c
@@ -6877,11 +6877,21 @@
    if ((sopt->sopt_level == SOL_SOCKET) &&
        (sopt->sopt_name == SO_SETFIB)) {
+       int optval;
+
+       error = sooptcopyin(sopt, &optval, sizeof(optval),
+           sizeof(optval));
+       if (error != 0)
+           return (error);
        inp = (struct sctp_inpcb *)so->so_pcb;
        if (inp == NULL) {
            SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ,
ENOBUFS);
            return (EINVAL);
        }
        SCTP_INP_WLOCK(inp);
-       inp->fibnum = so->so_fibnum;
+       error = sosetfib(so, optval);
+       if (error == 0)
+           inp->fibnum = optval;
        SCTP_INP_WUNLOCK(inp);
-       return (0);
+       return (error);
    }

-- 
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-300091-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 300091] [sctp] SO_SETFIB setsockopt() silently fails on SCTP
 sockets
Date: Mon, 26 Oct 2026 13:18:45 +0000
Organization: Newsgate at muc.de e.V.
Sender: owner-freebsd-bugs@FreeBSD.org
Approved: news-admin@muc.de
Distribution: world
Message-ID: <bug-300091-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="23085"; 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=1793020725;
	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=5CScXRq0w7sBdJxWGJkbqRPm+BD1B1hNHFfeHibX1Rg=;
	b=PkwNpLAXGUdTcv6fD8/41S53oqOrU8pl8Ct9cmZ+Gu4k8Qo0rJkBwS7Cytp98rp0FjMuQF
	JpL+pzLRTNY1zcqW/oELqeZtmMVCKiSo+Vq5JQ+fFc3SS/705Twe71jlEvnLxqzjqDij0i
	kK32TEiGJUX51KSwHyVg/+FaWe8gi5om10mzLBkQ/oEM4+OY7MoCCB0Dn2GmHFypJsbXCj
	z/PfvEU+6yalA43K1T2PMgqtABj1XVDEoJktuF3e5ap7yel52aUS3vrgnaYMBDk1+Dzapx
	4l8eC1gOYijxikNXaYoBBVKU5Du5E7fEFcd7j9xA0vruVdEZpV00hS5Wc/0iNw==
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