Project

General

Profile

Actions

Bug #9434

open
YL

app-layer: port-zero probing parser registrations can collide

Bug #9434: app-layer: port-zero probing parser registrations can collide

Added by yong liu 5 days ago. Updated 4 days ago.

Status:
In Review
Priority:
Normal
Assignee:
-
Target version:
Affected Versions:
Effort:
medium
Difficulty:
Label:
C

Description

Environment

  • Suricata branch: `main`
  • Affected component: `src/app-layer-detect-proto.c`
  • Function: `AppLayerProtoDetectInsertNewProbingParser()`

Problem

Port-independent probing parser registrations and port-based wildcard probing parser registrations can incorrectly reuse the same port-zero parser node.
Both registration types use `port = 0`, but they have different lookup semantics:

  • Port-independent registration: `use_ports = false`
  • Port-based wildcard registration: `use_ports = true`

In `AppLayerProtoDetectInsertNewProbingParser()`, the existing lookup condition checks the new registration's `use_ports` flag, but does not check the existing node's `curr_port->use_ports` flag.
As a result, when a port-independent parser has already registered a port-zero node, a subsequent wildcard registration can incorrectly reuse that node.
The wildcard parser is then attached to a node that is not used by port-based probing parser lookup. Consequently, the wildcard parser may not be detected on arbitrary destination ports.

Reproduction

The issue can be reproduced by registering a port-independent parser before a port-based wildcard parser for the same transport protocol.

For example, register:
1. A WebSocket probing parser with `portstr = NULL` (`use_ports = false`).
2. An SMTP probing parser with `portstr = "0"` (`use_ports = true`).

When the wildcard parser is incorrectly attached to the port-independent node, looking up probing parsers for a destination port such as TCP/6677 does not return the expected wildcard parser node.
The reverse registration order should also be tested to ensure both registration types remain independent.

Expected Behavior

Port-independent and port-based wildcard registrations should use separate parser nodes, even though both have `port = 0`.
Wildcard probing parsers should remain available through port-based lookup for arbitrary destination ports.

Actual Behavior

The registration logic may reuse an existing port-independent port-zero node for a wildcard registration because it does not check the existing node's `use_ports` flag.
This can cause wildcard probing parsers to be attached to a node that is ignored by port-based lookup.

Proposed Fix

When searching for an existing node to reuse, also check the existing node's `use_ports` flag:

if (curr_port->port == port && use_ports && curr_port->use_ports)
    break;

This prevents a port-based wildcard registration from reusing a port-independent node.

A regression test should cover both registration orders:
  • Port-independent parser followed by wildcard parser.
  • Wildcard parser followed by port-independent parser.
Actions

Also available in: PDF Atom