]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
http2: trigger raw stream reassembly
authorShivani Bhardwaj <shivani@oisf.net>
Thu, 8 May 2025 07:06:15 +0000 (12:36 +0530)
committerShivani Bhardwaj <shivanib134@gmail.com>
Thu, 15 May 2025 07:12:36 +0000 (12:42 +0530)
Internals
---------
Suricata's stream engine returns data for inspection to the detection
engine from the stream when the chunk size is reached.

Bug
---
Inspection triggered only in the specified chunk sizes may be too late
when it comes to inspection of smaller protocol specific data which
could result in delayed inspection, incorrect data logged with a transaction
and logs misindicating the pkt that triggered an alert.

Fix
---
Fix this by making an explicit call from all respective applayer parsers to
trigger raw stream reassembly which shall make the data available for inspection
in the following call of the stream engine. This needs to happen per direction
on the completion of an entity like a request or a response.

Important notes
---------------
1. The above mentioned behavior with and without this patch is
affected internally by the following conditions.
- inspection depth
- stream depth
In these special cases, the inspection window will be affected and
Suricata may not consider all the data that could be expected to be
inspected.
2. This only applies to applayer protocols running over TCP.
3. The inspection window is only considered up to the ACK'd data.
4. This entire issue is about IDS mode only.

HTTP2 has a classic request response model, so, a call to trigger raw
stream reassembly is added on completion of each request and response.
HTTP2 parser has its own maximum reassembly setting. The call has been
added irrespective of this setting as it is prudent to make all data so
far available for inspection if maximum was reached until the maximum.

Optimization 7026
Bug 7004

rust/src/http2/http2.rs

index 66035e0985f4a93099e96151b50928b0275b592c..c11d195013d55d3bbb130950bb015f188ba0fbe1 100644 (file)
@@ -32,12 +32,12 @@ use crate::frames::Frame;
 use crate::dns::dns::{dns_parse_request, dns_parse_response, DNSTransaction};
 
 use nom7::Err;
-use suricata_sys::sys::AppProto;
 use std;
 use std::collections::VecDeque;
 use std::ffi::CString;
 use std::fmt;
 use std::io;
+use suricata_sys::sys::AppProto;
 
 static mut ALPROTO_HTTP2: AppProto = ALPROTO_UNKNOWN;
 static mut ALPROTO_DOH2: AppProto = ALPROTO_UNKNOWN;
@@ -1282,6 +1282,7 @@ impl HTTP2State {
                             None => panic!("no SURICATA_HTTP2_FILE_CONFIG"),
                         }
                     }
+                    sc_app_layer_parser_trigger_raw_stream_reassembly(flow, dir as i32);
                     input = &rem[hlsafe..];
                 }
                 Err(Err::Incomplete(_)) => {
@@ -1491,9 +1492,7 @@ unsafe extern "C" fn http2_state_get_tx_count(state: *mut std::os::raw::c_void)
     return state.tx_id;
 }
 
-unsafe extern "C" fn http2_tx_get_state(
-    tx: *mut std::os::raw::c_void,
-) -> HTTP2TransactionState {
+unsafe extern "C" fn http2_tx_get_state(tx: *mut std::os::raw::c_void) -> HTTP2TransactionState {
     let tx = cast_pointer!(tx, HTTP2Transaction);
     return tx.state;
 }