Bug #9456
openebpf: flows created from pinned maps use an unset third VLAN id
Description
Affected versions: main since dc29ab46e ("ebpf: check maps compatibility"). main-8.0.x does not have that commit and still sets flow_key.vlan_id[2] = next_key.vlan2, so it is not affected.
Description¶
With XDP bypass and pinned-maps: true, Suricata reads the pinned flow_table_v4 / flow_table_v6 at start and creates a flow for each entry (EBPFForEachFlowV4Table() / EBPFForEachFlowV6Table() -> EBPFCreateFlowForKey() -> FlowGetFromFlowKey()).
The FlowKey for that lookup is a stack variable that is filled field by field. dc29ab46e removed vlan2 from struct flowv4_keys / struct flowv6_keys (the eBPF programs track two VLAN layers) together with the assignment of flow_key.vlan_id[2], so that field is left unset. FlowKeyGetHash() and CmpVlanIds() use all three VLAN ids when vlan.use-for-tracking is enabled, and the value is copied into the new flow.
Effects:
- the hash and the comparison of the flow depend on stack contents: the two half-flow entries of one bypassed flow can end up as two flows, or an entry may not match the flow created for its other direction;
- the flow carries a third VLAN id that was never on the wire.
Steps to reproduce¶
AF_PACKET with XDP bypass on a veth, pinned-maps: true, bpffs mounted, a rule with the bypass keyword.
- Start Suricata, send traffic that gets bypassed, stop Suricata (the entries stay pinned).
- Start Suricata again under valgrind on the same interface.
Script: sudo review3/run_multi.sh <build> true single vg 1 1 <outdir> restart (second instance log: <outdir>/p2/valgrind.log).
Observed¶
valgrind in the second instance: "Use of uninitialised value" / "Conditional jump or move depends on uninitialised value(s)" in FlowGetFromFlowKey() and CmpVlanIds() called from EBPFCreateFlowForKey(), and in CreateEveFlowId() when such a flow is logged.
Expected¶
vlan_id[2] of these flows is 0, as the eBPF keys hold two VLAN layers.
LS Updated by Lukas Sismis about 3 hours ago
- Affected Versions git main added
LS Updated by Lukas Sismis about 3 hours ago
- Affected Versions 8.0.8 added
- Affected Versions deleted (
git main)