On Mon, Sep 14, 2026 at 06:58:48AM +0200, Björn Ketelaars wrote:
> On Sun 13/09/2026 20:54, Zack Newman wrote:
> > To replicate this bug, I recommend using Linux for Peer 1; but it may be
> > fine to use OpenBSD so long as it's either before 7.7 or is not running
> > on a virtual machine and using vio(4). Using Arch Linux, the following
> > WireGuard configuration and bash(1) templates can be used to establish
> > the WireGuard connection:
> > 
> > [root@laptop ~]# cat /usr/local/etc/config_wg_vps
> > [Interface]
> > PrivateKey = AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAE=
> > ListenPort = 4987
> > 
> > [Peer]
> > PublicKey = rYxIwmdlrqetxTYolgXBq+qVBQCT29IYyWq9JIGgNWU=
> > Endpoint = [<peer2_ipv6_endpoint>]:4987
> > AllowedIps = fe80::2/128, 10.0.0.2/32
> > 
> > [root@laptop ~]# cat /usr/local/sbin/connect_wg_vps
> > #!/usr/bin/bash
> > 
> > /usr/bin/ip link add dev wg0 mtu 1420 type wireguard
> > /usr/bin/ip -6 address add local fe80::1/64 scope link dev wg0
> > /usr/bin/ip -4 address add local 10.0.0.1/30 broadcast + scope link dev wg0
> > /usr/bin/wg setconf wg0 /usr/local/etc/config_wg_vps
> > /usr/bin/ip link set dev wg0 up
> > 
> > When messing around with Peer 2, I simply ensure the above is modified
> > such that the IP version used to establish the tunnel is the same and the
> > MTU of wg0 is the same as the MTU of wg(4) on Peer 2.
> > 
> > Peer 2 will be the peer to tinker with. The below config and info will
> > exhibit the bug:
> > 
> > vps$ uname -a
> > OpenBSD vps.philomathiclife.com 7.9 GENERIC.MP#11 amd64
> > vps$ ifconfig vio0
> > vio0: flags=2008843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST,LRO> mtu 1500
> >     lladdr 52:54:00:0c:b2:d8
> >     index 1 priority 0 llprio 3
> >     groups: egress
> >     media: Ethernet autoselect
> >     status: active
> >     inet6 fe80::5054:ff:fe0c:b2d8%vio0 prefixlen 64 scopeid 0x1
> >     inet6 fe80::2%vio0 prefixlen 64 scopeid 0x1
> >     inet6 2607:f2f8:a600::1 prefixlen 128
> >     inet 10.0.121.2 netmask 0xfffffffc broadcast 10.0.121.3
> > vps# cat /etc/hostname.wg0
> > wgkey AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAI=
> > wgport 4987
> > wgpeer /TOE4TKtAqVsePRVR+5AA43HkAK5DSntkOCO7nYq5xU= wgendpoint 
> > <peer1_ipv6_endpoint> 4987 wgaip fe80::1/128 wgaip 10.0.0.1/32
> > inet6 fe80::2%wg0 64
> > inet 10.0.0.2 255.255.255.252 NONE
> > mtu 1420
> > 
> > First ensure the MTU of the physical connections are fine which for
> > Peers 1 and 2 in my setup are 1500:
> > 
> > [zack@laptop ~]# ping -6c1 -M do -s 1452 2607:f2f8:a600::1
> > PING 2607:f2f8:a600::1 (2607:f2f8:a600::1) 1452 data bytes
> > 1460 bytes from 2607:f2f8:a600::1: icmp_seq=1 ttl=54 time=46.2 ms
> > 
> > --- 2607:f2f8:a600::1 ping statistics ---
> > 1 packets transmitted, 1 received, 0% packet loss, time 0ms
> > rtt min/avg/max/mdev = 46.227/46.227/46.227/0.000 ms
> > 
> > vps$ ping6 -Dc1 -s 1452 2601:283:4e00:fdd4::2
> > PING 2601:283:4e00:fdd4::2 (2601:283:4e00:fdd4::2): 1452 data bytes
> > 1460 bytes from 2601:283:4e00:fdd4::2: icmp_seq=0 hlim=49 time=44.545 ms
> > 
> > --- 2601:283:4e00:fdd4::2 ping statistics ---
> > 1 packets transmitted, 1 packets received, 0.0% packet loss
> > round-trip min/avg/max/std-dev = 44.545/44.545/44.545/0.000 ms
> > 
> > Using ping(8) on Peer 1, we can see fragmentation occurs sooner than it
> > should:
> > 
> > [zack@laptop ~]# ping -6c1 -M do -s 1361 fe80::2%wg0
> > PING fe80::2%wg0 (fe80::2%wg0) 1361 data bytes
> > 
> > --- fe80::2%wg0 ping statistics ---
> > 1 packets transmitted, 0 received, 100% packet loss, time 0ms
> > [zack@laptop ~]# ping -4c1 -M do -s 1381 10.0.0.2
> > PING 10.0.0.2 (10.0.0.2) 1381(1409) bytes of data.
> > 
> > --- 10.0.0.2 ping statistics ---
> > 1 packets transmitted, 0 received, 100% packet loss, time 0ms
> > 
> > Similarly using ping6(8) and ping(8) on Peer 2, we observe premature
> > fragmentation:
> > 
> > vps$ ping6 -Dc1 -s 1361 fe80::1%wg0
> > PING fe80::1%wg0 (fe80::1%wg0): 1361 data bytes
> > 
> > --- fe80::1%wg0 ping statistics ---
> > 1 packets transmitted, 0 packets received, 100.0% packet loss
> > vps$ ping -Dc1 -s 1381 10.0.0.1
> > PING 10.0.0.1 (10.0.0.1): 1381 data bytes
> > 
> > --- 10.0.0.1 ping statistics ---
> > 1 packets transmitted, 0 packets received, 100.0% packet loss
> > 
> > A couple of interesting observations:
> > 
> > * I'm unable to replicate the bug when IPv4 is used to establish the
> >   tunnel (e.g., reducing the MTU of vio(4) to 1499 and setting the MTUs
> >   for the WireGuard peers to 1439 as well as changing the configuration
> >   such that IPv4 is used for the endpoints does not exhibit premature
> >   fragmentation).
> > * Installing OpenBSD on a physical machine and avoiding the use of
> >   vio(4) seems to prevent the bug from occurring.
> > 
> > I _highly_ suspect that commit c061998[^1] is partially, if not entirely,
> > responsible for this bug since:
> > 
> > * OpenBSD 7.6 (i.e., the most recent release _before_ that commit) does
> >   not exhibit this bug.
> > * OpenBSD 7.7 (i.e., the oldest release _after_ that commit) does exhibit
> >   this bug.
> > * While it seems to only affect vio(4) and IPv6, the bug is triggered
> >   when the MTU of wg(4) is:
> >   * Not a multiple of 16.
> >   * Greater than the MTU of vio(4) less 96 (but of course not bigger
> >     than the MTU of vio(4) less 80).
> > 
> > That commit, among other things, removed "clamping" of the plaintext
> > length such that the padding WireGuard performs does not exceed the MTU:
> > 
> > - plaintext_len = min(WG_PKT_WITH_PADDING(m->m_pkthdr.len), t->t_mtu);
> > + plaintext_len = WG_PKT_WITH_PADDING(m->m_pkthdr.len);
> > 
> > WireGuard expressly requires that padding not cause the underlying MTU
> > to be exceeded, so this violates the protocol.
> > 
> > [^1]: 
> > https://github.com/openbsd/src/commit/c06199859734d958552a581d72b4c0f910e68d7c
> > 
> > Obligatory dmesg(8) of my VPS with OpenBSD 7.9-stable installed:
> > 
> > vps$ dmesg
> > OpenBSD 7.9 (GENERIC.MP) #11: Thu Sep 10 09:48:01 MDT 2026
> >     
> > [email protected]:/usr/src/sys/arch/amd64/compile/GENERIC.MP
> > real mem = 2130554880 (2031MB)
> > avail mem = 2038546432 (1944MB)
> > random: good seed from bootblocks
> > mpath0 at root
> > scsibus0 at mpath0: 256 targets
> > mainbus0 at root
> > bios0 at mainbus0: SMBIOS rev. 2.8 @ 0xf5a90 (10 entries)
> > bios0: vendor SeaBIOS version "1.13.0-1ubuntu1.2~ppa1" date 04/01/2014
> > bios0: QEMU Standard PC (i440FX + PIIX, 1996)
> > acpi0 at bios0: ACPI 1.0
> > acpi0: sleep states S3 S4 S5
> > acpi0: tables DSDT FACP APIC HPET WAET
> > acpi0: wakeup devices
> > acpitimer0 at acpi0: 3579545 Hz, 24 bits
> > acpimadt0 at acpi0 addr 0xfee00000: PC-AT compat
> > cpu0 at mainbus0: apid 0 (boot processor)
> > cpu0: Westmere E56xx/L56xx/X56xx (Nehalem-C), 2598.16 MHz, 06-2c-01
> > cpu0: cpuid 1 
> > edx=78bfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2>
> >  ecx=82b82203<SSE3,PCLMUL,SSSE3,CX16,SSE4.1,SSE4.2,x2APIC,POPCNT,AES,HV>
> > cpu0: cpuid 6 eax=4<ARAT>
> > cpu0: cpuid 80000001 edx=20100800<NXE,LONG> ecx=1<LAHF>
> > cpu0: MELTDOWN
> > cpu0: 32KB 64b/line 8-way D-cache, 32KB 64b/line 8-way I-cache, 4MB 
> > 64b/line 16-way L2 cache, 16MB 64b/line 16-way L3 cache
> > cpu0: smt 0, core 0, package 0, type P
> > mtrr: Pentium Pro MTRR support, 8 var ranges, 88 fixed ranges
> > cpu0: apic clock running at 1000MHz
> > cpu1 at mainbus0: apid 1 (application processor)
> > cpu1: Westmere E56xx/L56xx/X56xx (Nehalem-C), 2599.02 MHz, 06-2c-01
> > cpu1: smt 0, core 0, package 1, type P
> > ioapic0 at mainbus0: apid 0 pa 0xfec00000, version 11, 24 pins
> > acpihpet0 at acpi0: 100000000 Hz
> > acpiprt0 at acpi0: bus 0 (PCI0)
> > "ACPI0006" at acpi0 not configured
> > acpipci0 at acpi0 PCI0
> > com0 at acpi0 COM1 addr 0x3f8/0x8 irq 4: ns16550a, 16 byte fifo
> > "PNP0303" at acpi0 not configured
> > "PNP0F13" at acpi0 not configured
> > acpicmos0 at acpi0
> > "PNP0A06" at acpi0 not configured
> > "PNP0A06" at acpi0 not configured
> > "PNP0A06" at acpi0 not configured
> > "QEMU0002" at acpi0 not configured
> > "ACPI0010" at acpi0 not configured
> > acpicpu0 at acpi0: C1(@1 halt!)
> > acpicpu1 at acpi0: C1(@1 halt!)
> > cpu0: using IvyBridge MDS workaround
> > pvbus0 at mainbus0: KVM
> > pvclock0 at pvbus0
> > pci0 at mainbus0 bus 0
> > pchb0 at pci0 dev 0 function 0 "Intel 82441FX" rev 0x02
> > pcib0 at pci0 dev 1 function 0 "Intel 82371SB ISA" rev 0x00
> > pciide0 at pci0 dev 1 function 1 "Intel 82371SB IDE" rev 0x00: DMA, channel 
> > 0 wired to compatibility, channel 1 wired to compatibility
> > atapiscsi0 at pciide0 channel 0 drive 1
> > scsibus1 at atapiscsi0: 2 targets
> > cd0 at scsibus1 targ 0 lun 0: <QEMU, QEMU DVD-ROM, 2.5+> removable
> > cd0(pciide0:0:1): using PIO mode 4, DMA mode 2
> > atapiscsi1 at pciide0 channel 1 drive 1
> > scsibus2 at atapiscsi1: 2 targets
> > cd1 at scsibus2 targ 0 lun 0: <QEMU, QEMU DVD-ROM, 2.5+> removable
> > cd1(pciide0:1:1): using PIO mode 4, DMA mode 2
> > uhci0 at pci0 dev 1 function 2 "Intel 82371SB USB" rev 0x01: apic 0 int 11
> > piixpm0 at pci0 dev 1 function 3 "Intel 82371AB Power" rev 0x03: apic 0 int 
> > 9
> > iic0 at piixpm0
> > vga1 at pci0 dev 2 function 0 "Cirrus Logic CL-GD5446" rev 0x00
> > wsdisplay0 at vga1 mux 1: console (80x25, vt100 emulation)
> > wsdisplay0: screen 1-5 added (80x25, vt100 emulation)
> > virtio0 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00
> > vio0 at virtio0: 1 queue, address 52:54:00:0c:b2:d8
> > virtio0: msix per-VQ
> > virtio1 at pci0 dev 4 function 0 "Qumranet Virtio SCSI" rev 0x00
> > vioscsi0 at virtio1: qsize 256
> > virtio1: msix per-VQ
> > scsibus3 at vioscsi0: 255 targets
> > sd0 at scsibus3 targ 0 lun 0: <QEMU, QEMU HARDDISK, 2.5+>
> > sd0: 40960MB, 512 bytes/sector, 83886080 sectors, thin
> > virtio2 at pci0 dev 5 function 0 "Qumranet Virtio Memory Balloon" rev 0x00
> > viomb0 at virtio2
> > virtio2: apic 0 int 10
> > virtio3 at pci0 dev 6 function 0 "Qumranet Virtio RNG" rev 0x00
> > viornd0 at virtio3
> > virtio3: apic 0 int 10
> > isa0 at pcib0
> > isadma0 at isa0
> > fdc0 at isa0 port 0x3f0/6 irq 6 drq 2
> > pckbc0 at isa0 port 0x60/5 irq 1 irq 12
> > pckbd0 at pckbc0 (kbd slot)
> > wskbd0 at pckbd0: console keyboard, using wsdisplay0
> > pms0 at pckbc0 (aux slot)
> > wsmouse0 at pms0 mux 0
> > pcppi0 at isa0 port 0x61
> > spkr0 at pcppi0
> > usb0 at uhci0: USB revision 1.0
> > uhub0 at usb0 configuration 1 interface 0 "Intel UHCI root hub" rev 
> > 1.00/1.00 addr 1
> > vscsi0 at root
> > scsibus4 at vscsi0: 256 targets
> > softraid0 at root
> > scsibus5 at softraid0: 256 targets
> > sd1 at scsibus5 targ 1 lun 0: <OPENBSD, SR CRYPTO, 006>
> > sd1: 40959MB, 512 bytes/sector, 83885488 sectors
> > root on sd1a (d20a86a935e384f6.a) swap on sd1b dump on sd1b
> > fd0 at fdc0 drive 1: density unknown
> > 
> 
> 
> wg_encap() rounds the plaintext up to a multiple of 16 with no upper
> bound:
> 
>     plaintext_len = WG_PKT_WITH_PADDING(m->m_pkthdr.len);
> 
> Over IPv6 the datagram on the wire is roundup16(inner) + 80. The default
> wg(4) MTU is 1420, and 1420 % 16 == 12, so a full size inner packet pads
> to 1424 and the datagram becomes 1504 on a 1500 byte link. ip6_output()
> then fragments it; wg_send() sets no IPV6_DONTFRAG), which is the
> premature fragmentation you see.
> 
> Your probe sizes land exactly on the boundary: 1361 + 8 + 40 and
> 1381 + 8 + 20 are both 1409 bytes inner, and 1409 is the first length
> that rounds past 1420.
> 
> You are right, the bound used to exist and was removed in the commit you
> mentioned.
> 
> I think that that two of your conclusions do not hold, though:
> - vio(4) is not involved. ip6_output() fragments before the packet ever
>   reaches the driver, and vio(4) sizes its tx ring off if_hardmtu. The
>   bug always produces fragmentation; whether that shows up as packet
>   loss depends on whether the path drops IPv6 fragments, which many VPS
>   networks do.
> - IPv4 is not immune. It looks that way because 1500 - 60 = 1440 is
>   already 16-aligned, so the usual IPv4 config has slack. Your 1499/1439
>   test needed a probe in the 1397..1411 range to trigger; at -s 1381 the
>   datagram is 1484 and fits.
> 
> Restoring the old min() is not the fix:
> 
>     plaintext_len = min(WG_PKT_WITH_PADDING(m->m_pkthdr.len), t->t_mtu);
> 
> Since WG_PKT_WITH_PADDING(len) >= len, this drops below len exactly when
> t_mtu < len. plaintext_len is then less than m_pkthdr.len, so
> padding_len underflows as size_t and out_len is sized too small while
> m_copydata() still copies m_pkthdr.len bytes. That is the memory
> corruption claudio removed.
> 
> Proposed is to to bound the padding instead of the plaintext.
> plaintext_len is then either roundup16(len) or len, both >= len, so
> neither the underflow nor the short buffer is reachable for any input.
> 
> Zack, does this clear it for you?

Should there be padding between 1408 and the default MTU of 1420?

e.g.

if (m->m_pkthdr.len <= t->t_mtu)
        plaintext_len = min(WG_PKT_WITH_PADDING(m->m_pkthdr.len), t->t_mtu);
else
        plaintext_len = WG_PKT_WITH_PADDING(m->m_pkthdr.len);

This should prevent those issues as well.
 
> diff --git sys/net/if_wg.c sys/net/if_wg.c
> index 0641c4b5ba9..10ef3b2f5c7 100644
> --- sys/net/if_wg.c
> +++ sys/net/if_wg.c
> @@ -1591,7 +1591,14 @@ wg_encap(struct wg_softc *sc, struct mbuf *m)
>       t = wg_tag_get(m);
>       peer = t->t_peer;
>  
> +     /*
> +      * Padding must never push the datagram past the tunnel MTU. Drop the
> +      * padding instead of clamping plaintext_len, so that plaintext_len can
> +      * never end up below m_pkthdr.len.
> +      */
>       plaintext_len = WG_PKT_WITH_PADDING(m->m_pkthdr.len);
> +     if (plaintext_len > t->t_mtu)
> +             plaintext_len = m->m_pkthdr.len;
>       padding_len = plaintext_len - m->m_pkthdr.len;
>       out_len = sizeof(struct wg_pkt_data) + plaintext_len +
>           NOISE_AUTHTAG_LEN;
> 

-- 
:wq Claudio

Reply via email to