🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: muc.lists.freebsd.bugs
3 messages
3 total messages Started by bugzilla-noreply Tue, 24 Nov 2026 11:39
[Bug 301077] ktls: software-fallback TCP_RXTLS_ENABLE leaks an ifnet reference per connection
#721
Author: 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
[Bug 301077] ktls: software-fallback TCP_RXTLS_ENABLE leaks an ifnet reference per connection
#723
Author: bugzilla-noreply
Date: Tue, 24 Nov 2026 11:39
16 lines
2465 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301077

--- Comment #1 from laamalif@proton.me ---
Created attachment 277643
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277643&action=edit
ktls-rx-ifp-leak-fix.patch

-- 
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
[Bug 301077] ktls: software-fallback TCP_RXTLS_ENABLE leaks an ifnet reference per connection
#722
Author: bugzilla-noreply
Date: Tue, 24 Nov 2026 11:39
16 lines
2458 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301077

--- Comment #2 from laamalif@proton.me ---
Created attachment 277644
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277644&action=edit
repro_rx_ifp_leak.c

-- 
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads