Bug 292162 - panic in in6_selecthlim when stopping a jail with vlan
Summary: panic in in6_selecthlim when stopping a jail with vlan
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 15.0-CURRENT
Hardware: arm64 Any
: --- Affects Only Me
Assignee: Gleb Smirnoff
URL:
Keywords: crash, ipv6
Depends on:
Blocks:
 
Reported: 2026-01-03 20:09 UTC by Justin Hibbits
Modified: 2026-01-22 03:15 UTC (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Justin Hibbits freebsd_committer freebsd_triage 2026-01-03 20:09:30 UTC
When stopping a jail on my arm64 system that has a vlan as well as an epair I get the following fully reproducible panic:

panic: vm_fault failed: 0xffff0000007366a4 error 1

with a backtrace of:

#0  0xffff000000519e98 in doadump (textdump=<optimized out>) at /usr/src/sys/kern/kern_shutdown.c:399
#1  0xffff000000519b18 in kern_reboot (howto=260) at /usr/src/sys/kern/kern_shutdown.c:519
#2  0xffff00000051a1bc in vpanic (fmt=<optimized out>, ap=...) at /usr/src/sys/kern/kern_shutdown.c:974
#3  0xffff000000519f60 in panic (fmt=0xffff000000d65000 <sysctl___security_bsd_unprivileged_idprio+32> "") at /usr/src/sys/kern/kern_shutdown.c:887
#4  0xffff000000936900 in data_abort (td=<optimized out>, frame=0xffff0001d6b43fb0, esr=2516582406, far=<optimized out>, lower=<optimized out>) at /usr/src/sys/arm64/arm64/trap.c:410
#5  <signal handler called>
#6  0xffff0000007366a4 in in6_selecthlim (inp=inp@entry=0xffffa0256bde5000, ifp=<optimized out>, ifp@entry=0xffff0001d6b44180) at /usr/src/sys/netinet6/in6_src.c:848
#7  0xffff0000006f6150 in tcp_default_output (tp=0xffffa0256bde5000) at /usr/src/sys/netinet/tcp_output.c:1447
#8  0xffff00000070ecbc in tcp_usr_disconnect (so=<optimized out>) at /usr/src/sys/netinet/tcp_usrreq.c:710
#9  0xffff0000005dbefc in sodisconnect (so=0xffff0001e26d5200) at /usr/src/sys/kern/uipc_socket.c:2149
#10 soclose (so=0xffff0001e26d5200) at /usr/src/sys/kern/uipc_socket.c:1945
#11 0xffff00000049b284 in fo_close (fp=fp@entry=0xffffa02473251d20, td=0x1c, td@entry=0xffffa02473251d20) at /usr/src/sys/sys/file.h:400
#12 _fdrop (fp=fp@entry=0xffffa02473251d20, td=0x1c, td@entry=0xffff0001b896bc80) at /usr/src/sys/kern/kern_descrip.c:3857
#13 0xffff00000049f630 in closef (fp=fp@entry=0xffffa02473251d20, td=td@entry=0xffff0001b896bc80) at /usr/src/sys/kern/kern_descrip.c:2952
#14 0xffff00000049e998 in fdescfree_fds (td=0xffff0001b896bc80, fdp=0xffff0001e26fa430) at /usr/src/sys/kern/kern_descrip.c:2669
#15 fdescfree (td=td@entry=0xffff0001b896bc80) at /usr/src/sys/kern/kern_descrip.c:2712
#16 0xffff0000004b6fa4 in exit1 (td=td@entry=0xffff0001b896bc80, rval=<optimized out>, rval@entry=-692828544, signo=<optimized out>, signo@entry=15) at /usr/src/sys/kern/kern_exit.c:403
#17 0xffff00000053dcec in sigexit (td=td@entry=0xffff0001b896bc80, sig=sig@entry=15) at /usr/src/sys/kern/kern_ucoredump.c:200
#18 0xffff00000051ed4c in postsig (sig=15) at /usr/src/sys/kern/kern_sig.c:3461
#19 0xffff00000052421c in ast_sig (td=0xffff0001b896bc80, tda=<optimized out>) at /usr/src/sys/kern/kern_sig.c:313
#20 0xffff00000058f7b4 in ast_handler (td=td@entry=0xffff0001b896bc80, framep=framep@entry=0xffff0001d6b448e0, dtor=<optimized out>) at /usr/src/sys/kern/subr_trap.c:366
#21 0xffff00000058f70c in ast (framep=0xffff0001d6b448e0) at /usr/src/sys/kern/subr_trap.c:376


None of my other jails, which only use epairs or tun's, cause a panic on stop.
Comment 1 Justin Hibbits freebsd_committer freebsd_triage 2026-01-03 20:56:29 UTC
An interesting datapoint, it seems to only get hit using iocage jails.  Converting my jail to a vanilla jail, I don't see the panic (on a single run).
Comment 2 Gleb Smirnoff freebsd_committer freebsd_triage 2026-01-04 00:20:58 UTC
What's an iocage jail and how I reproduce this?
Comment 3 Justin Hibbits freebsd_committer freebsd_triage 2026-01-04 04:03:59 UTC
(In reply to Gleb Smirnoff from comment #2)

An iocage jail is a jail created and managed by iocage (py311-iocage).

I think a jail can be created with:

iocage create -r 15.0-RELEASE -n broken ip4_addr="vnet0|192.168.1.9/24,shiot|192.168.42.3/24" ip6_addr="vnet0|fd00:1::9,vnet0|accept_rtadv" vnet_interfaces="shiot" interfaces="vnet0:bridge0" vnet=1 bpf=1


"shiot" is a VLAN created in the host on vlan 42, and handed to the iocage jail.  It's been a while since I created the jail, so that line might be off.
Comment 4 Kristof Provost freebsd_committer freebsd_triage 2026-01-04 16:44:08 UTC
I believe this is the same issue as #279653 and #291003.

We've also seen it on pfsense (https://redmine.pfsense.org/issues/14431). I believe the first reports there started about two years ago. At the time I stuck this workaround in the pfsense tree: https://github.com/pfsense/FreeBSD-src/commit/9834d8bb0d3344cd82552c3cd16e5b2d84543d8f (That's very much a workaround and not a fix, but it does seem to have greatly reduced the impact for pfsense users)

My suspicion is that it's a race around interface destruction, where we somehow still end up getting a route from fib6_lookup() on an interface that no longer has afdata for AF_INET6, but I never worked out how we could end up in that state.

We also never managed to get a reliable reproduction scenario. If Justin can reproduce this it'll be important progress.
Comment 5 Justin Hibbits freebsd_committer freebsd_triage 2026-01-05 01:34:42 UTC
(In reply to Kristof Provost from comment #4)

For me it's 100% reproducible using iocage to manage this jail.
Comment 6 Gleb Smirnoff freebsd_committer freebsd_triage 2026-01-05 17:01:29 UTC
I agree with Kristof that this is the same bug as all other open bugs that you would find searching for in6_selecthlim in subject.

The core problem is that the packet forwarding thread that catches the panic has nothing more than the network epoch for synchronization. When an interface departs, the struct ifnet and ifaddrs are freed with the epoch protection, but many protocols attached to departing ifnet are freed immediately. IPv6 is one of them. A proper fix is delayed epoch aware free of IPv6 bits.

Why did the panic became easier to reproduce in CURRENT? Because my 0d469d23715d has removed extra EPOCH_DRAIN_CALLBACKS(). This call did not provide a correct protection against the panic, but it reduced its probability a lot.

Why does other protocols don't panic in a similar way? Along with the epoch, we also got several relic mechanisms against interface departure races. One of the is if_dead, that a departing interface is assigned with output methods that won't dereference anything. Other is the protocols setting their ifp->if_foo softc to NULL on departure and doing a NULL check on every entry. None of these mechanisms is truly safe, but they reduce panic probabilities.

I plan to look at delayed free of IPv6 bits ASAP.
Comment 7 Gleb Smirnoff freebsd_committer freebsd_triage 2026-01-08 22:40:49 UTC
I got a branch that supposedly addresses the problem:

https://github.com/glebius/FreeBSD/tree/in6_ifextra

There are 8 commits there.  In principle change isn't complex, but diff is huge.
It passes netinet6 tests, but I didn't give it any testing beyond that.

Justin, if you can give it a try, that will be much appreciated.
Comment 8 Kristof Provost freebsd_committer freebsd_triage 2026-01-08 23:20:15 UTC
I'm seeing this panic running the pf tests:

panic: /usr/src/sys/netinet6/mld6.c:562: mld_domifdetach: Bad link elm 0xfffffe009abf21d8 prev->next != elm
cpuid = 1
time = 1767917830
KDB: stack backtrace:
db_trace_self_wrapper() at db_trace_self_wrapper+0xa5/frame 0xfffffe00989a1490
kdb_backtrace() at kdb_backtrace+0xc6/frame 0xfffffe00989a15f0
vpanic() at vpanic+0x214/frame 0xfffffe00989a1790
panic() at panic+0xb5/frame 0xfffffe00989a1860
mld_domifdetach() at mld_domifdetach+0x1d3/frame 0xfffffe00989a18a0
in6_ifdeparture() at in6_ifdeparture+0x74/frame 0xfffffe00989a18d0
if_detach_internal() at if_detach_internal+0x29b/frame 0xfffffe00989a19a0
if_detach() at if_detach+0x9e/frame 0xfffffe00989a19e0
enc_clone_destroy() at enc_clone_destroy+0x7e/frame 0xfffffe00989a1a10
if_clone_destroyif_flags() at if_clone_destroyif_flags+0xaf/frame 0xfffffe00989a1a60
if_clone_detach() at if_clone_detach+0x17e/frame 0xfffffe00989a1aa0
vnet_enc_uninit() at vnet_enc_uninit+0x61/frame 0xfffffe00989a1ac0
vnet_destroy() at vnet_destroy+0x233/frame 0xfffffe00989a1b10
prison_deref() at prison_deref+0x1339/frame 0xfffffe00989a1c70
sys_jail_remove() at sys_jail_remove+0x192/frame 0xfffffe00989a1d10
amd64_syscall() at amd64_syscall+0x3d5/frame 0xfffffe00989a1f30
fast_syscall_common() at fast_syscall_common+0xf8/frame 0xfffffe00989a1f30
--- syscall (508, FreeBSD ELF64, jail_remove), rip = 0xc697f43031a, rsp = 0xc697d504648, rbp = 0xc697d5046d0 ---
KDB: enter: panic
[ thread pid 4978 tid 100135 ]
Stopped at      kdb_enter+0x34: movq    $0,0x22a93b1(%rip)

with bricoler:
./bricoler run freebsd-src-regression-suite -p freebsd-src:url=/usr/src/ -p "freebsd-src-regression-suite:tests=sys/netpfil sbin/pfctl" -p freebsd-src-build:kernel_config=GENERIC-KASAN -p freebsd-src-regression-suite:hypervisor=bhyve -p freebsd-src:branch=""

(The /usr/src tree is main with your patches rebased on top, and the truss netlink changes, but I don't think those matter here.)
Comment 9 Gleb Smirnoff freebsd_committer freebsd_triage 2026-01-09 04:54:26 UTC
Thanks, Kristof. Indeed, mld has a global list over all structures and it isn't safe in the epoch based network stack. It should iterate over interfaces instead. I decided to leave that problem for later. Let's see if this is my error during refactoring, or indeed this problem needs to be fixed altogether with in6_ifextra delayed free.

I also caught a panic with ND after continuous testing.

So the branch isn't yet ready. Hold on, Justin, I'll update when I solve it.
Comment 10 Gleb Smirnoff freebsd_committer freebsd_triage 2026-01-09 19:39:39 UTC
Kristof, I can't reproduce your panic. Since you rebased my branch and mixed it with your changes, can you please double check that your resulting code has a line with a call to mld_domifdetach() removed from ip6_input.c:ip6_destroy()?
Comment 11 Kristof Provost freebsd_committer freebsd_triage 2026-01-09 20:36:22 UTC
(In reply to Gleb Smirnoff from comment #10)
It's indeed been removed in my version, I can see the patch doing it in my history as well.

I've re-run the test from your branch (e787bba72ff50184c2e666768ac0e967f9afaaa2) and it panics in the same way.  I'm not sure why we'd be seeing different results with bricoler runs.

#17 0xffffffff811f44a5 in panic (fmt=0xffffffff8229e4c0 <str> "%s:%u: %s: Bad link elm %p prev->next != elm") at /usr/src/sys/kern/kern_shutdown.c:887
#18 0xffffffff81639a43 in mld_domifdetach (ifp=<optimized out>) at /usr/src/sys/netinet6/mld6.c:562
#19 0xffffffff816141f4 in in6_ifdeparture (arg=<optimized out>, ifp=0xfffffe00ad725000) at /usr/src/sys/netinet6/in6_ifattach.c:938
#20 0xffffffff814479ab in if_detach_internal (ifp=ifp@entry=0xfffffe00ad725000, vmove=false) at /usr/src/sys/net/if.c:1089
#21 0xffffffff8144746e in if_detach (ifp=ifp@entry=0xfffffe00ad725000) at /usr/src/sys/net/if.c:1028
#22 0xffffffff8479538e in enc_clone_destroy (ifc=<optimized out>, ifp=0xfffffe00ad725000, flags=<optimized out>) at /usr/src/sys/net/if_enc.c:155
#23 0xffffffff8145660f in if_clone_destroyif_flags (ifc=ifc@entry=0xfffffe00cd316e00, ifp=0xfffffe00ad725000, flags=flags@entry=8) at /usr/src/sys/net/if_clone.c:457
#24 0xffffffff8145733e in if_clone_detach (ifc=0xfffffe00cd316e00) at /usr/src/sys/net/if_clone.c:675
#25 0xffffffff814571ba in ifc_detach_cloner (ifc=0xffffffff82a004e0 <panicstr>) at /usr/src/sys/net/if_clone.c:555
#26 0xffffffff847960e1 in vnet_enc_uninit (unused=<optimized out>) at /usr/src/sys/net/if_enc.c:408
#27 0xffffffff814c22d3 in vnet_sysuninit () at /usr/src/sys/net/vnet.c:640
#28 vnet_destroy (vnet=0xfffffe00cf64e180) at /usr/src/sys/net/vnet.c:295
#29 0xffffffff8117f959 in prison_deref (pr=<optimized out>, pr@entry=0xfffffe0099712000, flags=<optimized out>, flags@entry=85) at /usr/src/sys/kern/kern_jail.c:3589
#30 0xffffffff81182112 in prison_remove (pr=0xfffffe0099712000) at /usr/src/sys/kern/kern_jail.c:2919
#31 sys_jail_remove (td=<optimized out>, uap=<optimized out>) at /usr/src/sys/kern/kern_jail.c:2879
#32 0xffffffff81b8c1a5 in syscallenter (td=0xfffffe00bb586780) at /usr/src/sys/amd64/amd64/../../kern/subr_syscall.c:193
#33 amd64_syscall (td=0xfffffe00bb586780, traced=0) at /usr/src/sys/amd64/amd64/trap.c:1208
Comment 12 Gleb Smirnoff freebsd_committer freebsd_triage 2026-01-09 23:37:14 UTC
I have pushed a change that fixes the mld panic discovered by Kristof. The problem was there with enc(4) before my changes, but was surfaced by them.

I wasn't able to reproduce my yesterday panic with nd6/lle, despite running test for a day. My analysis also hint that the panic is there for a long time, but hard to hit.

Justin, please check if you can reproduce the in6_selecthlim panic with my branch.
Comment 13 Kristof Provost freebsd_committer freebsd_triage 2026-01-10 09:44:46 UTC
(In reply to Gleb Smirnoff from comment #12)
Thanks! I'm not sure why, but I triggered it reliably before your fix. I can no longer reproduce the panic now.
Comment 14 Gleb Smirnoff freebsd_committer freebsd_triage 2026-01-10 18:14:26 UTC
My custom VM didn't have enc(4) in the config, that's why didn't trigger for me. Ok, waiting for feedback from Justin.
Comment 15 Justin Hibbits freebsd_committer freebsd_triage 2026-01-11 03:24:15 UTC
(In reply to Gleb Smirnoff from comment #14)

It may be a few days before I can test, but I'll let you know as soon as I'm able.
Comment 16 Justin Hibbits freebsd_committer freebsd_triage 2026-01-11 21:12:16 UTC
(In reply to Gleb Smirnoff from comment #14)

I got a panic with your kernel:

panic: Misaligned access from kernel space!
cpuid = 9
time = 1768165796
KDB: stack backtrace:
db_trace_self() at db_trace_self
db_trace_self_wrapper() at db_trace_self_wrapper+0x38
vpanic() at vpanic+0x1a0
panic() at panic+0x48
align_abort() at align_abort+0xc0
handle_el1h_sync() at handle_el1h_sync+0x18
--- exception, esr 0x96000021
ip6_output() at ip6_output+0x958
tcp_default_output() at tcp_default_output+0x1dd4
tcp_disconnect() at tcp_disconnect+0xcc
tcp_usr_disconnect() at tcp_usr_disconnect+0x60
soclose() at soclose+0x8c
_fdrop() at _fdrop+0x28
closef() at closef+0x1f8
fdescfree() at fdescfree+0x420
exit1() at exit1+0x430
sigexit() at sigexit+0x14c
postsig() at postsig+0x114
ast_sig() at ast_sig+0x11c
ast_handler() at ast_handler+0xd4
ast() at ast+0x24
handle_el0_sync() at handle_el0_sync+0x70
Comment 17 Gleb Smirnoff freebsd_committer freebsd_triage 2026-01-12 01:31:22 UTC
Thanks, Justin! I don't have an arm64 to test. Can you please dig out the line of ip6_output+0x958?
Comment 18 Justin Hibbits freebsd_committer freebsd_triage 2026-01-12 02:56:32 UTC
(In reply to Gleb Smirnoff from comment #17)

It would probably help if I provided that...

/usr/home/chmeee/freebsd/sys/arm64/include/atomic.h:140 ... translate that to the right line in ip6_output.c and we get:

sys/netinet6/ip6_output.c:804
                in6_ifstat_inc(ifp, ifs6_out_request);
Comment 19 Justin Hibbits freebsd_committer freebsd_triage 2026-01-13 21:02:25 UTC
(In reply to Justin Hibbits from comment #18)

Oh, register dump, too:

  x1: 0xffffa026104f4800
  x2: 0xffffa0205c82f200
  x3: 0xffffa029926738e0
  x4: 0xffff0001d877ce78
  x5: 0x0000000000000008
  x6: 0x0000000000000000
  x7: 0x0000000000000000
  x8: 0xdeadc0dedeae50de
  x9: 0x0000000000000000
 x10: 0x0000000000009000
 x11: 0x0000000000000001
 x12: 0xffffa026104f4800
 x13: 0xffffa026104f4800
 x14: 0xffff000000d710b8 (rn_ones + 0x0)
 x15: 0xffffa027cda2de20
 x16: 0x0000000000000008
 x17: 0xffff0001d877ce80
 x18: 0xffff0000452d5000 ($d + 0x43885820)
 x19: 0xffffa02716170668
 x20: 0xffffa02716170540
 x21: 0xffffa026d58e0170
 x22: 0x0000000000000000
 x23: 0xffffa02716170688
 x24: 0xffff000000a79519 (do_execve.fexecv_proc_title + 0x39d55)
 x25: 0x0000000000000000
 x26: 0x0000000000000000
 x27: 0x0000000000000000
 x28: 0xffff0001d877d070
 x29: 0xffff0001d877d110
  sp: 0xffff0001d877cf80
  lr: 0xffff0000006dda38 (ip6_output + 0x890)
 elr: 0xffff0000006ddb00 (ip6_output + 0x958)
spsr: 0x0000000080000005
 far: 0xdeadc0dedeae50de
 esr: 0x0000000096000021


Looks like it's incrementing on freed memory.
Comment 20 Gleb Smirnoff freebsd_committer freebsd_triage 2026-01-15 03:28:35 UTC
It is expected that https://reviews.freebsd.org/D54721 will fix the panic.
Comment 21 Justin Hibbits freebsd_committer freebsd_triage 2026-01-15 16:43:15 UTC
(In reply to Gleb Smirnoff from comment #20)

Confirming, applying D54721 on main does fix this issue.
Comment 22 commit-hook freebsd_committer freebsd_triage 2026-01-17 00:44:24 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=f102a18349335bfda1eb373a64eb1ba7462cd6bb

commit f102a18349335bfda1eb373a64eb1ba7462cd6bb
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2026-01-17 00:38:02 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2026-01-17 00:38:02 +0000

    net: on interface detach purge all its routes before detaching protocols

    Otherwise, a forwarding thread may use the interface being detached.  This
    is a regression from 0d469d23715d, which manifests itself as a reliably
    reproducible panic in in6_selecthlim().  Note that there are old bug
    reports about such a panic, and I believe this change will not fix them,
    as their nature is not due to a screwed up detach sequence, but due to
    lack of proper epoch(9) based synchronization between the detach and
    forwarding.

    Reviewed by:            pouria
    Reported & tested by:   jhibbits
    PR:                     292162
    Fixes:                  0d469d23715d690b863787ebfa51529e1f6a9092
    Differential Revision:  https://reviews.freebsd.org/D54721

 sys/net/if.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Comment 23 Gleb Smirnoff freebsd_committer freebsd_triage 2026-01-22 03:15:48 UTC
Let's mark this one as fixed and use older bugs 279653 and 291003 that are still open to track the supposedly known and supposedly correctly diagnosed race.