Bug #9462
openDNS/TCP shared gap state suppresses later DNS transaction and alert
Description
- Summary
I found a Suricata DNS-over-TCP application-layer parsing state issue that can suppress a later DNS transaction and therefore suppress a matching alert. This report is a request for upstream confirmation, not a claim of a new CVE.
- Reproduction
The attached/referenced files are generated by `repro.py` from the official SU-006 fixture:
- `inputs/dns-gap-with-response.pcap`: trigger input
- `inputs/dns-gap-no-response.pcap`: negative control
- `rules/test.rules`: matches only `evil.test.com` (SID 1)
The trigger TCP payload sequence is:
```text
client -> server: 32-byte DNS query for www.test.com
client -> server: 10-byte TCP gap (represented by a sequence jump)
client -> server: 16-byte invalid DNS/TCP slice: 00 0e ff ff ...
server -> client: valid DNS response for www.test.com, 48-byte TCP payload
client -> server: the same 16-byte invalid slice
client -> server: 33-byte valid DNS query for evil.test.com
```
Run:
```sh
suricata -r inputs/dns-gap-with-response.pcap -c suricata.yaml \
-S rules/test.rules -l out-trigger -k none --runmode single
suricata -r inputs/dns-gap-no-response.pcap -c suricata.yaml \
-S rules/test.rules -l out-control -k none --runmode single
```
On the local F build, which already contains the public SU-006 one-line early-return fix, the trigger input produces the first DNS request and the reverse response but not the final `evil.test.com` transaction, emits no SID 1 alert, and reports one `dns_tcp` parser error. The negative control on the same F build keeps the request gap recovery state active, parses `evil.test.com`, emits SID 1, and reports zero `dns_tcp` parser errors. An older B image also contains the earlier SU-006 defect, so it is not used to isolate this shared-state behavior.
- Suspected cause
The request gap callback sets a single `DNSState.gap` flag. The request and response TCP parsers use that same flag. When the valid reverse response is recognized, the response parser clears the flag even though the request direction still has an unrecovered gap. The next invalid request slice then enters the normal parser with `gap == false`, returns a parser error, and the C app-layer framework disables application parsing for the flow. The subsequent valid request is therefore never exposed to detection.
The local trace records:
```text
request_gap|size=10|gap=true
response_probe|gap=true|is_dns=true|incomplete=false
response_clear|gap=false
request_entry|gap=false|len=16
request_error|gap=false|len=16
```
The likely state fix is to keep request and response gap state independent. A local F2 build that changes only the state scope to `gap_ts`/`gap_tc` restores the final DNS transaction and SID 1 on the trigger input while preserving the negative control. This is a causal experiment, not a proposed production patch; it still needs upstream design and regression review.
- Evidence and versions
- Local affected source lineage for the shared-state reproduction: the F build is based on the `c48bb1b26c71c2f840e2b9f2e41709029bced707` image and includes the public SU-006 early-return fix; the image digest is recorded in `manifest.json`.
- Frozen comparison binary: local commit `eec7819ca6d8c477d34b4ccfe4cf70bb25d7274c`, also reproduces the shared-state behavior in this test.
- Official base fixture: SU-006 / issue 8842 input; the generated trigger and control PCAPs are new deterministic derivatives.
- Two repeats per input and variant were recorded. Raw EVE, stderr, commands, source diffs and SHA-256 manifests are retained in the local artifact.
- Questions for upstream
1. Is sharing one DNS/TCP gap flag across request and response directions intentional?
2. Does current `main` or a maintained release still reproduce the trigger/control distinction?
3. If the behavior is valid, what is the preferred fix and regression-test shape?
4. Can an upstream regression test be added for a valid reverse response arriving between two invalid request slices after a TCP gap?
- Caveats
This is a controlled synthetic PCAP, not proof of exploitability or prevalence on live traffic. Please confirm packet validity, affected versions, and security impact independently.
Files
No data to display