Security #9133
closeddoh2: xbits track-tx type confusion crashes the detection engine
e221a72ed992c03f6c8c29bceaabe14d2f80c385
Description
- Summary
Suricata 8.0.7 treats a DoH2 transaction as HTTP/2 when fetching `AppLayerTxData`, but the detection path that actually runs for `xbits:isset,...,track tx` on a DoH2 flow has already swapped the transaction pointer to the inner `DNSTransaction`. `http2_get_tx_data` then adds the HTTP/2 `tx_data` offset to a DNS object. On the toclient path that offset lands past the `HTTP2Transaction`, `TxBitIsset` loads a small integer from the next object's DoH DATA buffer length, and the worker segfaults. Unauthenticated DNS-over-HTTP/2 traffic is enough. The two attachments in this directory replay that crash: one live, one as a suricata-verify test.
- Affected version
Confirmed on `jasonish/suricata:8.0.7` ("This is Suricata version 8.0.7 RELEASE"). Default yaml already has `http2` and `doh2` enabled.
- Preconditions
- IDS/IPS is inspecting TCP that the HTTP/2 parser will accept as cleartext h2c (or decrypted HTTP/2).
- The flow is classified `ALPROTO_DOH2`: request or response carries `content-type: application/dns-message` (GET with a `dns=` query string also works) and the body / query decodes as a DNS message.
- A loaded rule uses an explicit app hook plus `xbits:isset,<name>,track tx`. In 8.0.7 `DetectGetInnerTx` returns NULL for a DoH2-engine hook (`alert doh2:...`), so the reachable form is a DNS hook on that DoH2 flow, for example `alert dns:response_started any any > any any (xbits:isset,bit1,track tx; sid:1;)`. That is supported syntax, not a disabled safety check. `xbits:set,track tx` is post-match on the outer HTTP/2 tx and does not hit this sink. The crash is `isset` + `track tx` + an app hook whose inner tx is DNS.
- Impact
The capture thread dies with SIGSEGV (container exit 139, kernel `segfault` on `TxBitIsset`). The process stops inspecting traffic. This is a detection-engine crash, not a stable write primitive and not RCE.
- Vulnerable code
`DetectXbitTxMatch` always asks for tx data with the flow protocol:
```c
AppLayerTxData *txd = AppLayerParserGetTxData(f->proto, f->alproto, txv);
int r = TxBitIsset(txd, xd->idx);
```
On a DoH2 flow `f->alproto` is `ALPROTO_DOH2`, so `AppLayerParserGetTxData` calls `http2_get_tx_data` (`lea 0x328(%rdi)` / offset 808). `txv` is not an `HTTP2Transaction`.
`DetectGetInnerTx` for DoH2:
- `engine_alproto == ALPROTO_DNS` → `txv = SCDoH2GetDnsTx(http2_tx, flags)`
- `engine_alproto` is DoH2 itself → `txv = NULL` and the engine is skipped
- `ALPROTO_HTTP2` keeps the outer tx (correct `GetTxData`, no crash)
`SCDoH2GetDnsTx` returns the nested DNS object (`dns_request_tx` at HTTP2+0xE0 for toserver, `dns_response_tx` at HTTP2+0x200 for toclient). Those objects are 288-byte `DNSTransaction` values stored inside `HTTP2Transaction.doh`, not standalone HTTP/2 txs.
`TxBitIsset` / `TxBitGet` read `txd->txbits` at `+0x30` and, if non-NULL, dereference it as a `GenericVar` (`cmpw $0x1e, (%rax)` at `TxBitIsset+0x19`).
- Root cause
DoH2 is HTTP/2 plus an inner DNS transaction. Detection correctly peels the inner DNS tx for DNS keywords, then incorrectly reuses the flow alproto to interpret that pointer as HTTP/2. The HTTP/2 `tx_data` offset (808) applied to the toclient DNS pointer (HTTP2+512) yields HTTP2+1320, which is past the 1152-byte `HTTP2Transaction`. The qword used as `txbits` is then whatever sits 216 bytes into the next inlined tx in the `VecDeque` (on this build, `doh.data_buf1.len`, the still-open toserver DATA length). A non-zero length becomes a pointer and `TxBitIsset` faults.
Toserver `isset` on the request DNS tx overlays `ft_ts.cur_ooo_chunk_offset` (usually 0). `TxBitGet` returns without a deref, so a single completed POST often does not crash. Multiplexed HTTP/2 with a later stream that still has toserver DATA buffered makes the toclient path crash reliably.
- Call chain
1. af-packet worker sees h2c DoH POST (`content-type: application/dns-message`).
2. HTTP/2 parser `handle_headers` / `handle_dns_data` parses DNS and `SCAppLayerForceProtocolChange(ALPROTO_DOH2)`.
3. `DetectRunTxInspectRule` → `DetectGetInnerTx(..., ALPROTO_DOH2, ALPROTO_DNS, STREAM_TOCLIENT)` → `SCDoH2GetDnsTx`.
4. `DetectEngineInspectGenericList` → `DetectXbitTxMatch`.
5. `AppLayerParserGetTxData(TCP, ALPROTO_DOH2, dns_tx)` → `http2_get_tx_data`.
6. `TxBitIsset` loads a small integer and dereferences it → SIGSEGV.
- Payload
Cleartext HTTP/2, no TLS required for this parser:
- Stream 1: POST `/dns-query` with `content-type: application/dns-message` and a valid DNS query, `END_STREAM` on request. Server returns `content-type: application/dns-message` and a DNS response with `END_STREAM`.
- Streams 3/5/7: same POST headers plus DATA without `END_STREAM`, so `doh.data_buf[toserver]` stays populated on the next `HTTP2Transaction`.
A single-stream GET/POST is enough to reach `DetectXbitTxMatch`; the extra open streams are what turn the type confusion into a fault on this layout.
- Reproduction
Two attachments share the same bug and differ by prefix: `e2e-doh2-xbits-tx-type-confusion.tar.gz` and `verify-doh2-xbits-tx-type-confusion.tar.gz`. Default `http2` / `doh2`. The rule is `alert dns:response_started` with `xbits:isset,bit1,track tx`. `-k none` is only needed for the crafted pcap.
e2e-doh2-xbits-tx-type-confusion.tar.gz — live h2c on a Docker bridge, `jasonish/suricata:8.0.7`. Unpack and run `./verify.sh`. The engine loads the rules, the client finishes stream 1 and leaves streams 3/5/7 without `END_STREAM`, and the Suricata container exits 139. `dmesg` shows `segfault at e6` inside `TxBitIsset`. `./stop_env.sh` removes the containers afterwards.
verify-doh2-xbits-tx-type-confusion.tar.gz — suricata-verify test (`input.pcap` + `test.yaml` + `test.rules` + `writepcap.py`). Copy the unpacked directory into your suricata-verify `tests/` tree and, from a built Suricata source tree:
```text
python3 ../path/to/suricata-verify/run.py doh2-xbits-tx-type-confusion
```
Unpatched `./src/suricata` dies (runner: `got exit code -11, expected 0`, i.e. SIGSEGV). The same pcap with detection disabled exits 0, logs a DNS response for `example.com`, and marks the flow `app_proto: doh2`. After a fix the engine should finish and those checks should pass. `writepcap.py` rebuilds `input.pcap` with the standard library only.
- Follow-up information from the reporter
Yes. Current main still crashes, but the 8.0.7 rule does not reach it.
I retested jasonish/suricata:main-amd64, Suricata 9.0.0-dev (git 9b7938aec, 2026-09-17).
DetectGetInnerTx has changed. On 8.0.7 a DNS engine on a DoH2 flow receives the inner DNS transaction, so this rule crashes:
```text
alert dns:response_started any any -> any any (xbits:isset,bit1,track tx; sid:1;)
```
On main that DNS engine is skipped. The DoH2 engine is now the one that peels out the inner DNS transaction, and DetectXbitTxMatch still calls AppLayerParserGetTxData with the flow alproto (doh2, so http2_get_tx_data). The same pcap with the 8.0.7 rule loads and exits 0. This rule SIGSEGVs the worker (exit 139, dmesg: segfault at e6 in TxBitIsset):
```text
alert doh2:stream:response_started any any -> any any (xbits:isset,bit1,track tx; sid:1;)
```
DoH2 hooks on main need a substate (stream or global).
Attachments:
1. e2e-doh2-xbits-main.tar.gz
Live h2c against jasonish/suricata:main-amd64. Unpack and run ./verify.sh. The container exits 139. ./stop_env.sh cleans up.
2. verify-doh2-xbits-main.tar.gz
suricata-verify test doh2-xbits-tx-type-confusion. Copy it under tests/ and run it from a main tree. Unpatched ./src/suricata dies with SIGSEGV (runner: exit code -11, expected 0). With detection disabled the same pcap exits 0, logs a DNS response, and marks the flow app_proto doh2. After a fix those checks should pass.
The traffic is the same shape as the 8.0.7 report: one completed DoH POST, plus a later stream whose toserver DATA has no END_STREAM (length 230).
JI Updated by Jason Ish about 2 months ago
- Target version set to 9.0.0-beta1
- Label Needs backport to 8.0 added
OT Updated by OISF Ticketbot about 2 months ago
- Subtask #9134 added
OT Updated by OISF Ticketbot about 2 months ago
- Label deleted (
Needs backport to 8.0)
PA Updated by Philippe Antoine about 2 months ago
- Status changed from New to Triaged
- Severity set to HIGH
PA Updated by Philippe Antoine about 2 months ago
HIGH severity as type confusion read-only from network traffic
VJ Updated by Victor Julien about 2 months ago
- Status changed from Triaged to In Review
- Assignee changed from OISF Dev to Victor Julien
GL
JI Updated by Jason Ish about 1 month ago
- GHSA set to GHSA-32wc-5hmh-wj5j
PA Updated by Philippe Antoine 25 days ago
- Status changed from In Review to Resolved
staged