Security #9161
Updated by Jason Ish about 2 months ago
Hello, This is a disclosure for a vulnerability in Suricata that was found by Anthropic using their models and agents. I have reviewed the vulnerability and consider it to be true according to Suricata's threat model. h3. ### BSD defrag policy can undo an earlier trim, so Suricata reassembles different bytes than the target host h3. ### TLDR The vulnerability is that the BSD overlap handling in @DefragInsertFrag()@ `DefragInsertFrag()` in @src/defrag.c@ `src/defrag.c` overwrites the left-trim (@ltrim@) (`ltrim`) of the next fragment instead of only raising it (lines 694 and 716). A fragment that arrives later can therefore lower a trim that an earlier fragment already set. This brings back bytes that should have been replaced. Because reassembly copies fragments in offset order, those old bytes are copied last and win. The reassembled packet that Suricata inspects then differs from the one a BSD-style host builds, so an attacker can hide the bytes a signature looks for. BSD is Suricata's default defrag policy (@default_policy (`default_policy = DEFRAG_POLICY_BSD@), DEFRAG_POLICY_BSD`), and the same code is in main and in the 7.0.x and 8.0.x branches. Both IPv4 and IPv6 use this code. h3. ### Root cause @ltrim@ `ltrim` tells reassembly how many bytes at the start of a stored fragment have been replaced by other fragments. It must only grow. The @prev@ `prev` update at lines 708-713 respects this: it only writes @prev_ltrim@ `prev_ltrim` if it is larger than the current value. The @next@ `next` update at lines 715-717 (and 693-695) does not. It always writes @frag_end `frag_end - next->offset@, next->offset`, even when @next->ltrim@ `next->ltrim` is already larger because of an earlier overlap. _[Editorial *[Editorial omission: detailed trigger analysis, vulnerable code excerpts, and execution dataflow are not reproduced here.]_ here.]* h3. ### Suggested fix Make the @next@ `next` update work like the @prev@ `prev` update, so it only ever raises the trim. Apply this at both places (lines 693-695 and 715-717): <pre><code class="c"> ```c if ((next != NULL) && && (frag_end > next->offset)) > next->offset)) { uint16_t next_ltrim = frag_end - next->offset; next->offset; if (next_ltrim > next->ltrim) > next->ltrim) { next->ltrim next->ltrim = next_ltrim; } } </code></pre> ``` _[Editorial *[Editorial omission: the specific fragment sequence requested for the unit test is not reproduced here.]_ here.]* h3. ### Reproducer (suricata-verify test) _[Editorial *[Editorial omission: operational reproducer details and execution instructions are not reproduced here. The source report includes @test.yaml@, @test.rules@, @suricata.yaml@, `test.yaml`, `test.rules`, `suricata.yaml`, and @input.pcap@.]_ `input.pcap`.]* h3. ### Disclosure This report follows a 90-day coordinated disclosure deadline. I'm happy to coordinate on the exact timing and to provide any further detail you need. h3. ### Attribution Please attribute Anthropic and Ada Logics. This issue was found by Anthropic by using agents to study security of open source projects, and I have helped validate the found issue, create the report and communicate it to you.