Bug #9450
opendecode/erspan: Type II header decoder events never fire
Description
ERSPAN Type II is decoded by DecodeERSPAN(), which runs on the tunnel packet that DecodeGRE() creates with PacketTunnelPktSetup(). When the ERSPAN header check fails, DecodeERSPAN() sets a decoder event on the tunnel packet and returns TM_ECODE_FAILED. PacketTunnelPktSetup() treats that as an invalid tunnel and returns the tunnel packet to the packet pool, so its events are lost with it.
As a result, these never fire for ERSPAN Type II over GRE:
- erspan.header_too_small (sid 2200105)
- erspan.unsupported_version (sid 2200106)
The decoder.event.erspan.* counters for them also stay at 0, because the discarded packet is never counted.
erspan.too_many_vlan_layers (sid 2200107) can't trigger either. A tunnel packet starts with vlan_idx 0, and ERSPAN is the first layer decoded in it, so the check is dead code.
ERSPAN Type III had the same problem. The fix for #8329 checks the Type III header on the GRE packet before setting up the tunnel packet, as VXLAN does (review on https://github.com/OISF/suricata/pull/16688).
Proposed fix:
- Check the Type II header on the GRE packet before setting up the tunnel packet, and set the events there. This is the same approach as ERSPAN Type III and VXLAN.
- Remove the dead too_many_vlan_layers check.
- Keep the erspan.too_many_vlan_layers event, so that older rule files using it still load. Removing it makes rule loading fail under T / --init-errors-fatal, which breaks the suricata-verify event-rules* tests.
- Remove rule 2200107 from rules/decoder-events.rules, since it can no longer fire.
- Add a suricata-verify test that checks that rules 2200105 and 2200106 fire for Type II.
JF Updated by Juliana Fajardini Reichow 2 days ago
- Status changed from New to In Review
- Assignee set to Johan Ryberg
PR for review: https://github.com/OISF/suricata/pull/16713/