Project

General

Profile

Actions

Bug #9455

open
LS LS

ebpf: entries of idle bypassed flows are removed from pinned XDP maps at shutdown

Bug #9455: ebpf: entries of idle bypassed flows are removed from pinned XDP maps at shutdown

Added by Lukas Sismis about 3 hours ago. Updated about 3 hours ago.

Status:
Triaged
Priority:
Normal
Assignee:
Target version:
Affected Versions:
Effort:
Difficulty:
Label:

Description

Affected versions: main since 9ab8fa19d ("flow: update bypassed flows on shutdown/recycle"). main-8.0.x does not have that commit (its recycler does not poll bypassed flows), so it is not affected.

Description

With xdp-filter-file, bypass: yes and pinned-maps: true, the XDP filter and its flow tables stay in place when Suricata exits. The user guide (capture-hardware/ebpf-xdp, "Pinned maps usage") describes this as keeping the bypassed flow tables active so Suricata is not hit by previously bypassed flows after a restart. At start Suricata opens the pinned maps and creates flows for the entries it finds.

At shutdown all flows still in the flow table are passed to the flow recycler, which since 9ab8fa19d polls each capture-bypassed flow through BypassUpdate(). EBPFBypassUpdate() deletes both map keys of a flow for which the XDP filter counted no packet since the flow's previous poll; it does not look at the flow timeout. So such a flow is removed from the pinned map even if that poll happened moments before the stop and the bypass timeout is far from reached, and its packets reach Suricata again after the restart. A flow that was never polled is removed if no packet was counted since the bypass was set up. Only flows that had traffic between their last poll and the stop keep their entries.

Measured on main with flow-timeouts.udp.bypassed: 15: flows that the flow manager had polled and found active 6 ms, 1 s and 2 s before the stop were removed.

Steps to reproduce

AF_PACKET with XDP bypass on a veth, pinned-maps: true, bpffs mounted, flow-timeouts.udp.bypassed: 100, rule alert udp any any -> any 9999 (content:"BYPASSME"; bypass; sid:1;).

  1. Send a single UDP packet to port 9999. The flow is bypassed; the pinned flow_table_v4 has 2 entries.
  2. Stop Suricata (SIGTERM) a few seconds later.
  3. bpftool map dump pinned /sys/fs/bpf/suricata-<iface>-flow_table_v4

Script: repro/run_xdp.sh <build> 1 true <outdir>.

Observed

The pinned map is empty after the stop.

Expected

The entries stay in the pinned map and the next Suricata instance picks them up. Entries are still removed at shutdown for maps that do not outlive the process: unpinned XDP maps and maps of eBPF socket filters (unlinked at exit).

Actions

Also available in: PDF Atom