Project

General

Profile

Actions

Security #9425

open
AB

ipfw: autofp reinjects divert packets with another packet's sockaddr

Security #9425: ipfw: autofp reinjects divert packets with another packet's sockaddr

Added by Adam Barnard 2 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
Affected Versions:
Label:
CVE:
Git IDs:
Severity:
Disclosure Date:
GHSA:

Description

Reported to 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 with recvfrom() into the per-queue nq->ipfw_sin (src/source-ipfw.c:266-268 on main at e4f6fa728).
  • IPFWSetVerdict() reinjects with sendto() using the same nq->ipfw_sin (:564).
  • In workers mode, receive and verdict run back to back in one thread, so the sockaddr is always the packet's own.
  • In autofp the 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 when sin_addr is 0 and inbound otherwise, takes the interface from sin_zero, and sets pf's divert direction (idir) from sin_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 at sin_port + 1 (sys/netinet/ip_divert.c:369 on releng/15.1) and sets the packet's receive interface from the interface name in sin_zero (:381). Both come from the sockaddr Suricata passes to sendto().
  • 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 autofp runmode, ipfw divert rules, 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 the workers runmode.
  • 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 as EACCES from a later deny rule, IPFWSetVerdict() treats any error other than EHOSTDOWN/ENETDOWN as 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-size option from #9280) and kern.ipc.maxsockbuf at 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, or autofp-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 IPFW 3 passed, 0 failed; the full unit test suite 2714 passed, 0 failed. It applies unchanged to suricata-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 autofp runmode, ipfw divert rules (pf divert-to isn'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. autofp is 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

Actions

Also available in: PDF Atom