Security #9425
openipfw: autofp reinjects divert packets with another packet's sockaddr
Description
Reported to security@oisf.net on 2026-11-12; filed as a private (security) ticket herein per the security team's suggestion.
Problem¶
In IPFW mode with the autofp runmode, which is the IPFW default, Suricata reinjects a share of divert packets with another packet's divert sockaddr. On FreeBSD that sockaddr tells the kernel which direction and interface to reinject on, and carries pf's divert direction cookie, so a misdirected packet can be sent the wrong way or diverted a second time. With ipfw divert rules it also carries the rule to resume at which means the bug can change how the firewall evaluates the reinjected packet (see Security impact).
Cause¶
ReceiveIPFWLoop()receives each packet withrecvfrom()into the per-queuenq->ipfw_sin(src/source-ipfw.c:266-268on main at e4f6fa728).IPFWSetVerdict()reinjects withsendto()using the samenq->ipfw_sin(:564).- In
workersmode, receive and verdict run back to back in one thread, so the sockaddr is always the packet's own. - In
autofpthe verdict runs in a separate thread, and uses the sockaddr of whichever packet the receive thread read last. The field is also written and read by two threads without a lock. - This dates from the initial IPFW support, 2b7b78f1b (2010), which kept the sockaddr in a file global and already ran the verdict in its own thread. 6e7a8f38b (2011) moved it into the per-queue
IPFWQueueVars.
Effect on FreeBSD with pf divert-to¶
div_send()reinjects outbound whensin_addris 0 and inbound otherwise, takes the interface fromsin_zero, and sets pf's divert direction (idir) fromsin_port.- A data segment reinjected with an ACK's sockaddr goes back inbound, is forwarded, and is diverted a second time on the way out, so it arrives late. TCP sees the reordering and retransmits spuriously.
Security impact with ipfw divert rules¶
- With ipfw,
div_send()resumes rule processing atsin_port + 1(sys/netinet/ip_divert.c:369on releng/15.1) and sets the packet's receive interface from the interface name insin_zero(:381). Both come from the sockaddr Suricata passes tosendto(). - A packet reinjected with another packet's sockaddr can therefore resume at another divert rule's position and skip the rules in between, or be matched by later interface rules (
recv,in via) as if it had arrived on another interface. This means traffic from an untrusted interface could be given a trusted interface's policy. - An inbound packet reinjected with an outbound packet's sockaddr is sent to
ip_output()and skips the rest of the inbound rule pass. - Which sockaddr a packet borrows depends on the order of packets on the divert socket, which traffic from outside the host can influence. In the test setup below, about 5% of reinjections used the other direction's sockaddr with ordinary traffic.
- Conditions: the
autofprunmode, ipfwdivertrules, and firewall rules after the divert rule that depend on rule position or receive interface. - Not affected: pf
divert-to, because pf diverts only after the packet has passed its rules in that direction, so the effects there are the functional ones above; and theworkersrunmode. - Suricata's own inspection isn't bypassed: every packet still get inspected, and a dropped packet doesn't get reinjected. The issue is in how the firewall evaluates accepted packets after reinjection.
- Availability: with pf, the misdirected reinjections cut throughput (autofp at 26-58 Mbit/s against about 1150-1230 in workers in the tests below), and traffic from outside could likely raise the share of misdirected packets (not measured). With ipfw, an inbound packet reinjected with an outbound packet's sockaddr goes through
ip_output()and the output rules. If that returns an error, such asEACCESfrom a laterdenyrule,IPFWSetVerdict()treats any error other thanEHOSTDOWN/ENETDOWNas fatal, the verdict thread stops, and all diverted traffic stops. - This impact comes from analysis of the FreeBSD and Suricata source. I Haven't yet demonstrated against a real ruleset.
Evidence¶
FreeBSD 15.1 VM, vnet jails, pf divert-to for both directions, about 20 ms emulated RTT, iperf3 single-stream downloads of 20 s, builds with the FreeBSD CI job's CFLAGS:
- Unpatched main (e4f6fa728), autofp, default divert buffer: DTrace on
recvfrom()/sendto()counted 2603 of 52349 and 2613 of 53126 reinjections (5.0% and 4.9%) sent with the other direction's sockaddr. Throughput is capped at about 18 Mbit/s there by divert socket overflows, which hide the problem. - With a 4 MB divert receive buffer (the
ipfw.buffer-sizeoption from #9280) andkern.ipc.maxsockbufat 16 MiB: workers ran at about 1150-1230 Mbit/s; autofp ran at 26-58 Mbit/s with 300-480 retransmits per run. - In one autofp run DTrace counted 4608 data segments and 4615 ACKs reinjected with the wrong sockaddr, and about 4700 data segments were diverted twice. Every retransmission was DSACKed, and no packet was lost.
- Diverting only one direction, so that every packet carries the same sockaddr: autofp ran at about 1247 Mbit/s with no retransmits.
- Changing
max-pending-packets(64, 4096), the worker count, orautofp-scheduler(ippair) left autofp at 29-48 Mbit/s.
Workaround: runmode: workers. With ipfw, this also removes the security impact above.
Proposed fix (patch attached)¶
The attached patch carries the received sockaddr with the packet: it adds it to IPFWPacketVars, has ReceiveIPFWLoop() receive into a local and copy it into p->ipfw_v (via a helper the unit tests also use), and has IPFWSetVerdict() reinject with the packet's copy. That also removes the unlocked shared write. A tunnel packet is verdicted through its root, the packet read from the socket, so the root's sockaddr is used. sizeof(Packet) doesn't change.
- Three unit tests use UDP sockets on the loopback address in place of a divert socket, so the peer that receives a reinjected packet shows which sockaddr was used: two packets verdicted after both were received, a dropped packet, and a tunnel packet.
- main + patch:
-U IPFW3 passed, 0 failed; the full unit test suite 2714 passed, 0 failed. It applies unchanged tosuricata-8.0.8: 3 and 2694 passed, 0 failed. - Default buffer, autofp: 0 of 54974 and 0 of 55213 reinjections on the other direction's sockaddr.
- 4 MB buffer, autofp: 1208 Mbit/s with no retransmits in two runs (58 Mbit/s with 438 retransmits without the patch). workers: 1164-1228 Mbit/s with it, 1215-1230 without, four runs each.
After assessment, please advise whether you would like me to open a pull request now, or wait until this is public.
I think this issue could be characterized as either Low or Moderate. Here are my thoughts for your consideration:- Low: The bypass needs a specific, non-default combination: the
autofprunmode, ipfwdivertrules (pfdivert-toisn't affected), and firewall rules after the divert rule that depend on rule position or receive interface. Suricata's own inspection isn't evaded. - Moderate: where those conditions hold, the effect is a firewall-policy bypass, which can expose the hosts the firewall protects rather than only reduce visibility.
autofpis the IPFW default runmode, so an ipfw setup that doesn't choose a runmode is in scope. Traffic from outside the host can influence which sockaddr a packet borrows. The code dates from 2010, so every release with IPFW support is likely affected.
AI disclosure: I used Claude Fable 5.2 to support analysis of this issue but I've reviewed the materials myself.
Files
No data to display