Project

General

Profile

Actions

Security #9160

closed
JI JI

defrag: bsd policy only trims the immediate right neighbour

Security #9160: defrag: bsd policy only trims the immediate right neighbour

Added by Jason Ish about 2 months ago. Updated 7 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Affected Versions:
Label:
CVE:
Git IDs:

b5effe7f8e8a51155353277a749e317e985ce2e9
de91327f3450daf737e89d84cb64003be148d7a1

Severity:
LOW
Disclosure Date:
12/31/2026

Description

  1. Summary

In src/defrag.c, DefragInsertFrag() handles overlaps for DEFRAG_POLICY_BSD
in two places (the new fragment starts at or after the start of the
previous one, and the new fragment starts before it). Both do the same
thing to the fragments to the right of the new one:

```c
if ((next != NULL) && (frag_end > next->offset)) {
next->ltrim = frag_end - next->offset;
}
goto insert;
```

Only the single `next` fragment is trimmed and then we jump to `insert`. If
the new fragment also covers the fragments after `next`, those are left
untouched. Defrag4Reassemble() / Defrag6Reassemble() later copy the
fragments in tree order, so an untrimmed later fragment is written over the
bytes of the new fragment. With BSD policy the new fragment should have won
those bytes, so Suricata reassembles a different datagram than a BSD host
does.

  1. Confirmed present in

- oisf/main @ 7ad9874c050188cc3cf4c7eafdf90a277f534fb7

  1. Impact

A remote attacker who can send IP fragments through the sensor can make
Suricata reassemble a different payload than a host using the BSD policy.
For example, fragments at offsets 0, 16 and 32 (16 bytes each, all MF=1),
then a 40 byte fragment at offset 8 carrying the real payload, then a last
fragment at offset 48. The BSD policy keeps the earlier data for bytes 8-15
and takes the new fragment for bytes 16-47. Suricata trims only the
fragment at offset 16, so the fragment at offset 32 is left intact and its
benign data overwrites bytes 32-47 of the new fragment during reassembly.
Any signature that depends on the content or offsets in the reassembled
datagram can be evaded this way. The same code is used for IPv4 and IPv6.

  1. Preconditions

the destination is handled with the BSD policy (the default_policy in
defrag.c is BSD, or host-os-policy maps the target to bsd) and the attacker
can send raw fragments past the sensor.

  1. Proposed fix

Walk forward from `next` and trim every fragment the new one overlaps,
marking fully covered ones to be skipped, in both BSD branches:

```c
for (Frag *n = next; n != NULL && frag_end > n->offset;
n = IP_FRAGMENTS_RB_NEXT(n)) {
if (frag_end >= n->offset + n->data_len)
n->skip = 1;
else
n->ltrim = frag_end - n->offset;
}
```

  1. Validation status

For issue 1 we traced the fragment sequence above through
DefragInsertFrag() and the reassembly code by hand, both with and without
the change.

  1. Attachments

- `0001-defrag-bsd-trim-all-overlapped-fragments.patch` (issue 1)
- `regression_test_snippet_defrag.c` (issue 1, four tests, IPv4 and IPv6)

  1. Suggested severity

Our view, we'll defer to your assessment:

issue 1 looks MEDIUM (remotely triggerable detection bypass, but only for the BSD policy)

  1. Credit

Please credit Alexander Stadnikov and CC Luukas Larinkoski; no other individuals need to be named.


Files


Subtasks 1 (0 open — 1 closed)

Security #9163: defrag: bsd policy only trims the immediate right neighbour (8.0.x backport)ClosedJason IshActions

Related issues 1 (0 open — 1 closed)

Related to Suricata - Security #9161: defrag: BSD overlap can undo an earlier left trimClosedJason IshActions

JI Updated by Jason Ish about 2 months ago Actions #2

  • Status changed from New to Assigned
  • Assignee changed from OISF Dev to Jason Ish
  • Target version set to 9.0.0-beta1
  • Label Needs backport to 8.0 added

OT Updated by OISF Ticketbot about 2 months ago Actions #3

  • Subtask #9163 added

OT Updated by OISF Ticketbot about 2 months ago Actions #4

  • Label deleted (Needs backport to 8.0)

JI Updated by Jason Ish about 2 months ago Actions #5

  • Related to Security #9161: defrag: BSD overlap can undo an earlier left trim added

JI Updated by Jason Ish about 2 months ago Actions #6

  • Status changed from Assigned to In Review

JI Updated by Jason Ish about 2 months ago · Edited 1Actions #7

  • Severity set to LOW

Recommendations:

Severity:

│ Low, CVSS 3.1 3.7 (AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:L/A:N), CWE-437.
│ Limited to evasion of payload inspection; the required fragment overlap is
│ still detected and alerted on by the decoder event rules (sid 2200070/2200072).

Impact:

│ With the BSD defrag policy (default), a fragment overlapping several later
│ fragments only trimmed the first, so crafted IPv4/IPv6 fragments can make
│ Suricata inspect different data than the host reassembles, evading rules.

JI Updated by Jason Ish about 1 month ago Actions #8

  • Subject changed from BSD defrag policy only trims the immediate right neighbour to defrag: bsd policy only trims the immediate right neighbour

JI Updated by Jason Ish about 1 month ago Actions #9

  • GHSA set to GHSA-rh3v-3ff8-9cwx

JI Updated by Jason Ish 25 days ago Actions #10

  • Git IDs updated (diff)

JI Updated by Jason Ish 25 days ago Actions #11

  • Status changed from In Review to Closed

JI Updated by Jason Ish 7 days ago Actions #12

  • Private changed from Yes to No
Actions

Also available in: PDF Atom