🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: muc.lists.freebsd.bugs
6 messages
6 total messages Started by bugzilla-noreply Tue, 24 Nov 2026 22:03
[Bug 301093] wg(4): wg_timers_disable() fails to drain peer callouts
#733
Author: bugzilla-noreply
Date: Tue, 24 Nov 2026 22:03
108 lines
6410 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301093

            Bug ID: 301093
           Summary: wg(4): wg_timers_disable() fails to drain peer
                    callouts
           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

wg_timers_disable() calls callout_stop() on five wg(4) peer callouts
and can return while a handler is still using the peer.
NET_EPOCH_WAIT() does not cover a handler that has started, and every
handler uses the peer before or without an epoch section. The peer is
later freed by an epoch callback. Stock 15.1 showed wg_peer_destroy()
overlapping a running handler without an uninstrumented access after free.

At main 72d7d152c2ff, sys/dev/wg/if_wg.c lines 1045-1049 are:

        callout_stop(&peer->p_new_handshake);
        callout_stop(&peer->p_send_keepalive);
        callout_stop(&peer->p_retry_handshake);
        callout_stop(&peer->p_persistent_keepalive);
        callout_stop(&peer->p_zero_key_material);

Import 744bfb213144 contains the same stops; the functions used ck_pr_*
then and use atomic_* now.
The callouts are MPSAFE, so c_lock is NULL and the argument is
the raw peer. The last noise_remote_put() schedules
noise_remote_smr_free(), which calls wg_peer_free_deferred()
(if_wg.c:447) and then frees the remote.

On 15.1-RELEASE-p7 GENERIC amd64
(releng/15.1-n283696-bb03631fe3b7), DTrace matched both pointer and peer ID;
pointer-only matching produced 3793 false hits. In 4096- and 3072-destroy
runs, it recorded five wg_peer_destroy() entries while the
corresponding retry handler was running. Four measured tails were 56.1,
7.7, 60.6, and 14.3 microseconds. The free landed after
the handler. The host remained up through those 7168 destroys and the
other counted remove runs of 256, 384, 400, and 768.

wg_busy adds peers with persistent-keepalive 1 and removes them
at 5167 ms. The interface must already be up, with a private
key; pubs.bin holds raw 32-byte keys. On
16.0-CURRENT GENERIC-KASAN amd64 (main-6edecf52def6-dirty),
the same remove with no added delay completed:

    $ cc -Wall -Wextra -Werror -o wg_busy wg_busy.c -lnv
    $ cpuset -l 7 ./wg_busy wg0 pubs.bin 32 1 5167
    round=0 remove_off_ms=5167.0
    round=0 remove_done_ms=5167.9 ioctl_ms=0.9
    DONE

chill_fault.d holds noise_create_initiation() for 50 ms only when the retry
handler calls it. This widens the observed overlap enough for the deferred
free to finish before the handler's next access. In another terminal:

    # dtrace -w -s chill_fault.d

With dtrace running, round 0 completed and round 1 panicked.
The SSH connection terminated before the probe printed.
/var/crash/vmcore.3:

    panic: ASan: Invalid access, 8-byte read at 0xfffffe015d8eb540,
UMAUseAfterFree(fd)
    cpuid = 0
    noise_create_initiation() at noise_create_initiation+0x138
    wg_timers_run_send_initiation() at wg_timers_run_send_initiation+0x11d
    wg_timers_run_retry_handshake() at wg_timers_run_retry_handshake+0x1a3
    softclock_call_cc() at softclock_call_cc+0x33c

The faulting load was r->r_local from the freed noise_remote.
As a control, chill_verify.d delays the return after the peer accesses;
the free landed during that delay without fault.

The patch replaces the five stops with callout_drain(). Built as
if_wg.ko (sha256
db98411e38b9ba5a7d3ed5b14b549aeddf834cf4c179ad546308d0444ff94333)
against that KASAN kernel, the same 50 ms delay ran four rounds
with no panic. The remove ioctls took 55.6, 213.8, 101.0, and
243.9 ms, and all 128 frees ran after the handler returned. No handler
takes sc_lock, which wg_peer_destroy holds across the disable.

Peer removal requires local privilege. A configured peer can
schedule a timer but cannot remove itself.
On 15.1-RELEASE-p7 a root in a vnet jail created wg5, set
persistent-keepalive 1, sent 296 bytes, and removed the peer.
The remove ran in the host kernel and completed without a jail escape
or a host panic.

The patch was exercised as the if_wg module on the CURRENT KASAN
kernel only; 15.1-RELEASE, 14.4, arm64, and a full kernel build
are untested.

-- 
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 301093] wg(4): wg_timers_disable() fails to drain peer callouts
#734
Author: bugzilla-noreply
Date: Tue, 24 Nov 2026 22:03
16 lines
2434 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301093

--- Comment #1 from laamalif@proton.me ---
Created attachment 277665
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277665&action=edit
wg_callout_drain.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 301093] wg(4): wg_timers_disable() fails to drain peer callouts
#735
Author: bugzilla-noreply
Date: Tue, 24 Nov 2026 22:03
16 lines
2421 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301093

--- Comment #2 from laamalif@proton.me ---
Created attachment 277666
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277666&action=edit
wg_busy.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
[Bug 301093] wg(4): wg_timers_disable() fails to drain peer callouts
#736
Author: bugzilla-noreply
Date: Tue, 24 Nov 2026 22:03
16 lines
2426 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301093

--- Comment #3 from laamalif@proton.me ---
Created attachment 277667
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277667&action=edit
chill_verify.d

-- 
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 301093] wg(4): wg_timers_disable() fails to drain peer callouts
#737
Author: bugzilla-noreply
Date: Tue, 24 Nov 2026 22:03
16 lines
2425 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301093

--- Comment #4 from laamalif@proton.me ---
Created attachment 277668
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277668&action=edit
chill_fault.d

-- 
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 301093] wg(4): wg_timers_disable() fails to drain peer callouts
#739
Author: bugzilla-noreply
Date: Tue, 24 Nov 2026 23:08
16 lines
2515 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301093

Mark Linimon <linimon@FreeBSD.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|bugs@FreeBSD.org            |net@FreeBSD.org

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