[Bug 296598] inbound ipsec packets get tracked via outer ip header when the tunnel runs over if_wg
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 16 Jul 2026 12:23:34 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296598
--- Comment #6 from Lars Krämer <lkr@wizard.de> ---
I think I may have found the cause for this, and why it is only present with
if_wg.
Running this:
dtrace -x nolibs -qn '
fbt::enc_hhook:entry
/arg0 == 3/ {
this->enc = *(uint8_t *)((uintptr_t)arg3 + 25);
this->mp_ptr = *(uintptr_t *)arg3;
this->m = *(uintptr_t *)this->mp_ptr;
this->mdata = *(uintptr_t *)(this->m + 16);
this->mnext = *(uintptr_t *)(this->m + 0);
this->mnext_len = *(int *)(this->mnext + 24);
this->ipp = *(uint8_t *)(this->mdata + 9);
this->mlen = *(int *)(this->m + 24);
printf("enc_hhook IPSEC_IN stage=%d m=%p m_data=%p m_len=%d m_next=%p
m_next_len=%d ip_p=%d\n",
this->enc, this->m, this->mdata, this->mlen, this->mnext, this->mnext_len,
this->ipp);
}'
Gives me this output:
enc_hhook IPSEC_IN stage=1 m=fffff80022ed4700 m_data=fffff80022ed4768 m_len=20
m_next=fffff800635c6a00 m_next_len=60 ip_p=4
enc_hhook IPSEC_IN stage=2 m=fffff80022ed4700 m_data=fffff80022ed4768 m_len=0
m_next=fffff800635c6a00 m_next_len=60 ip_p=4
The packet is stored inside an mbuf chain. The head only contains the outer IP
header, 20 bytes.
ipsec4_common_input_cb calls m_striphdr to remove 20 bytes of IP header from
the packet.
This just sets the length of the mbuf to zero.
The mbuf head is now length zero.
This mbuf gets passed down like this until it reaches pf_test, where the IP
header gets read via mtod.
This is basically a pointer cast, reading the old header data from the buffer.
This also explains why the issue is only present with if_wg, and not with
wireguard-go.
The dtrace from above with wireguard-go looks like this (without m_next_len,
this time):
enc_hhook IPSEC_IN stage=1 m=fffff80058132800 m_data=fffff8005813285c m_len=60
m_next=0 ip_p=4
enc_hhook IPSEC_IN stage=2 m=fffff80058132800 m_data=fffff80058132870 m_len=40
m_next=0 ip_p=6
wireguard-go hands over the packet as a single mbuf, probably because it's
coming from userspace, avoiding the bug.
--
You are receiving this mail because:
You are the assignee for the bug.