🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

[Bug 301077] ktls: software-fallback TCP_RXTLS_ENABLE leaks an ifnet reference per connection

#721
From: bugzilla-noreply
Date: Tue, 24 Nov 2026 11:39
85 lines
5410 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301077

            Bug ID: 301077
           Summary: ktls: software-fallback TCP_RXTLS_ENABLE leaks an
                    ifnet reference per connection
           Product: Base System
           Version: 16.0-CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: laamalif@proton.me

Every TCP_RXTLS_ENABLE that falls back to software decryption
leaks one reference on the socket's receive interface.
ktls_alloc_rcv_tag() calls if_ref(ifp) and stores ifp in
tls->rx_ifp before checking the interface for IFCAP2_RXTLS4/6.
On an interface without receive TLS offload the checks fail and
the function returns EOPNOTSUPP with rx_ifp still set;
ktls_enable_rx() then calls ktls_use_sw(), which does not clear
the field. ktls_destroy() releases rx_ifp only in the
TCP_TLS_MODE_IFNET case; the TCP_TLS_MODE_SW case releases
nothing, so the reference from the enable is held until reboot.
An interface that is destroyed afterwards is never freed:
if_rele() is the only path to if_free_deferred().

(sys/kern/uipc_ktls.c, verified on main d5f0768e13f3:
if_ref at the head of ktls_alloc_rcv_tag; the IFNET-case release
in ktls_destroy. The same code is on stable/15, releng/15.1,
and releng/14.4.)

An unprivileged process triggers it: socket, connect,
setsockopt(TCP_RXTLS_ENABLE) with an AES-128-GCM key, close.
No packets are needed. Every software-fallback enable on a
host leaks one reference on the route interface; a busy
TLS terminator leaks one per connection.

Observed on 16.0-CURRENT GENERIC-KASAN (main-6edecf52def6-dirty,
Nov 22 2026 build), dtrace fbt::if_ref:entry printing
lo0's if_refcount during the runs:

10 AES-GCM enables on 127.0.0.1 connections, all sockets closed:

  if_ref ifp=...f19a7800 idx=2 name=lo0 refcount=56
  ...
  if_ref ifp=...f19a7800 idx=2 name=lo0 refcount=65

lo0's refcount rises from 55 to 65, one per enable, and stays
there; an if_rele predicate on the same interface fires zero
times in the trace. The kernel exports if_refcount through no
sysctl, so the count is read from the dtrace probe.

Control: 10 ChaCha20-Poly1305 enables, also completing in
software mode, take no reference at all - zero if_ref probes.
ktls_alloc_rcv_tag() returns ENXIO for ChaCha before the
if_ref, because ChaCha has no recrypt session
(ktls_ocf.c sets recrypt_csp only in the AES-GCM case). The
leak is specific to the ciphers that reach the reference.

The attached patch releases rx_ifp in the TCP_TLS_MODE_SW case of
ktls_destroy(), mirroring the IFNET case. I booted a
GENERIC-KASAN kernel built from the same source plus the patch
(build 2026-11-24): the same 10-enable run takes the 10
references as before and now releases all 10 at close, ending
at the baseline refcount (the trace shows if_ref counts 13 to
22 and ten if_rele counts back down to 13). The ChaCha control
is unchanged on the patched kernel: no references taken. An
epair created and destroyed around a 20-enable run frees both
pair interfaces cleanly.

Not tested on arm64; the destroy path is architecture
independent. I have not tested the patch on any release
branch.

-- 
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-301077-227@https.bugs.freebsd.org/bugzilla/>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: bugzilla-noreply@freebsd.org
Newsgroups: muc.lists.freebsd.bugs
Subject: [Bug 301077] ktls: software-fallback TCP_RXTLS_ENABLE leaks an ifnet
 reference per connection
Date: Tue, 24 Nov 2026 11:39:34 +0000
Organization: Newsgate at muc.de e.V.
Approved: news-admin@muc.de
Distribution: world
Message-ID: <bug-301077-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="14576"; 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=1795520374;
	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=IbWNor+Ok5xyRHGom58Z6HniRFRywfPTtam+ICYCSA4=;
	b=UvfbOxW65j3PywZ52RfU2obkWQNpdRcMfRiYOPBCnrjiydoI50rdMKdY20LVbEgOQOyfOa
	kvD2AqCwptl9IdLiBSy5VL/TjAwy47SOQ2FAEgy7vkO8yVfuYCwEGPngAYImMfMcSBgh5B
	TfMFgYNbc12JHZYgzmD8vpcLRwQeIuo3C6CY/wLd7nqYHSRIJ6ACSHjGRmsZBEjPVyMIpk
	psM5j00flexviMAF+BzciKuzNskDqVdNEW2fA13sP5ok6IGC9r4Hchs5qOXFJrF1mir0Zh
	qr8ufXTwU82NfHn/CKP1lXrBYrGsjqyONGvFJYYWE8EhA2M5KGhTCL+ZerjEKA==
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