Inside the Machine That Reads Your Mail

Site Admin · 4 Dec 2026 · Monitoring & Detection

Suricata never sees a message. It sees chunks of a TCP stream, reassembled into lines, fed into a state machine that must remember where it is. This is the pipeline from wire to verdict, and the eight fields of MimeStateSMTP that have to be correct for every part.

Suricata never sees a message. It sees chunks of a TCP stream, reassembled into lines, fed into a state machine that must remember where it is. Every one of those handoffs is a place where an attacker can disagree with the parser.

From wire to verdict

The pipeline has five stages:

  1. Capture. AF_PACKET, eBPF, PF_RING, DPDK or a pcap file delivers packets. The runmode — single, autofp or workers — decides how threads share the work.
  2. Decode and flow. Ethernet, IP, TCP are decoded; a flow hash table keeps per-connection state. TCP is reassembled into an ordered byte stream.
  3. Application layer. A parser is selected by port and protocol detection. It consumes the stream and builds transactions: one HTTP request/response, one SMTP message, one MQTT publish.
  4. Detection. The rule engine prefilters with a multi-pattern matcher, then evaluates the candidate rules against the transaction's buffers — payload, headers, file data, file name, URL.
  5. Output. Alerts and protocol records are serialised to EVE JSON, fast.log, pcap or a Lua script.

The important word is transaction. Rules do not run on packets. They run on the parser's model of a transaction.

The SMTP path in 8.0

In Suricata 8, src/app-layer-smtp.c handles the SMTP conversation and hands each line of the DATA block to a Rust parser:

MimeSmtpParserResult ret = SCSmtpMimeParseLine(
        line->buf, line->len, line->delim_len, &events, tx->mime_state);

The Rust struct is MimeStateSMTP. It carries the parser's entire memory of the message:

pub struct MimeStateSMTP<'a> {
    state_flag: MimeSmtpParserState,
    headers: Vec<MimeHeader>,
    main_headers_nb: usize,
    filename: Vec<u8>,
    attachments: Vec<Vec<u8>>,
    urls: Vec<Vec<u8>>,
    boundaries: Vec<Vec<u8>>,
    encoding: MimeSmtpEncoding,
    decoder: Option<base64::Decoder>,
    content_type: MimeSmtpContentType,
    decoded_line: Vec<u8>,
    bufeol: [u8; 2],
    bufeolen: u8,
    ...
}

boundaries is a stack: a multipart message pushes a boundary, a nested part pushes another, and the closing delimiter pops it. main_headers_nb marks where the top-level headers end, so the parser can truncate back to them when a part finishes. encoding and decoder say how the current body is encoded. content_type says whether the body is text, HTML, a message or unknown.

When the parser sees Content-Type: message/rfc822, it sets an encap flag and re-enters the header state: the inner message is a message inside the message. Everything in that struct has to be correct for the inner part, because the inner part inherits nothing from the RFC — it inherits whatever the code failed to clear.

The 7.0 path

Suricata 7 uses the C MIME decoder in src/util-decode-mime.c. It has the same shape — a state object, a boundary stack, an encoding enum, a partial-line buffer — but it decodes base64 and quoted-printable incrementally. Quoted-printable holds a small bvremain array for an escape sequence that has not finished: a = at the end of one call, waiting for the two hex digits in the next.

That partial buffer is the seam CVE-2026-57228 lives in. Streaming decoders are allowed to be called with any chunk size, including a one-byte chunk. The code assumed the chunk would be big enough.

Why chunk boundaries are attacker territory

TCP is a byte stream. It has no message boundaries, no line boundaries and no promise that a write arrives in one segment. An attacker controls segmentation: send one byte per segment, or end a segment precisely between = and 4.

Every parser that carries state across calls must handle every split point. The MIME parser handles most of them deliberately — bufeol exists to catch a boundary split across two chunks. The quoted-printable decoder handled the common cases and missed the one-byte tail.

This is not a coding style problem. It is the fundamental difficulty of writing a streaming parser against hostile input: the state machine must be total. Any missing transition is reachable, because the attacker can choose the chunking that triggers it.

Detection sits on top

The rule engine does not know any of this. It asks the transaction for file.data, file.name, url or the raw payload buffer. If the parser put the wrong bytes there, or failed to open a file at all, the rule silently evaluates an incomplete model.

That is why parser bugs in an IDS are not ordinary memory-safety bugs. A crash is visible. A wrong model is not. The rule returns "no match", the alert pipeline stays quiet, and the operator records a clean day.

Part 6 looks at the other fourteen security entries in the same 8.0.6 release.

Next: Part 6 — sixteen fixes in one release: the smaller failures that show how wide the parser surface really is.