An AS_PATH is a list of segments; a mask is a pattern; the matcher records
where the pattern lands. The record is a stack array with 2048 + 1 slots —
and the sender chooses how many positions the path produces.

The attribute

BGP's AS_PATH is a sequence of segments. Each segment is:

segment type   1 byte    AS_SET = 1, AS_SEQUENCE = 2
segment length 1 byte    number of ASNs, max 255
ASNs           length × 2 or 4 bytes

An AS_SEQUENCE is an ordered path. An AS_SET is an unordered set, used for
aggregation. A path can contain multiple segments, and the total number of
ASNs is bounded only by the message size.

Historically that bound was 4096 bytes per BGP message. RFC 8654 introduced
BGP Extended Messages, raising the ceiling to 65535 bytes. That change
matters here: with 2-byte ASNs, 4096 bytes allows at most ~2048 ASNs; with
extended messages, a peer can send far more.

The mask

BIRD's filter language compiles an expression like:

bgp_path ~ [= * 64500 64501 =]

into a pattern that must be aligned against the path. The matcher walks the
path and records, for each position, where the pattern's elements line up. The
positions are stored in pm_pos, a fixed-size array of 2048 + 1 entries on
the stack
.

The + 1 is a sentinel. The 2048 is the design bound: real internet paths are
tens of ASNs long, so 2048 is generous. The bug is that the code trusts that
generosity instead of enforcing it.

The producer/consumer gap

Two functions disagree about the bound:

  • parse_path() expands AS_PATH segments from a received UPDATE. It does
    not enforce a position-count limit.
  • as_path_match() stores positions in pm_pos. It does not check the
    array bound before writing.

An established peer sends a path whose expansion exceeds 2048 positions. The
matcher writes past the end of the stack array. That is the CWE-121 stack-based
buffer overflow in the advisory.

What a stack overflow means here

A stack buffer overflow in a routing daemon is the most dangerous class of
memory bug:

  1. It is a write primitive, not a read.
  2. It is on the stack, where saved return addresses and frame pointers
    live.
  3. It is in the process that speaks BGP to untrusted peers.

With stack canaries and non-executable stacks, a crude overflow usually aborts
the process — a remote denial of service from any peer. With an info leak and
a capable attacker, it can become control-flow hijack — code execution as the
routing daemon.

What is not published

The advisory does not publish the arithmetic that turns a received path into
more than 2048 positions. Three possibilities remain open:

  • the mask's shape (repeated wildcards, nested alternatives) multiplies
    positions non-linearly with path length;
  • the path arrives through a code path other than a single UPDATE — a
    concatenation or filter state;
  • extended messages simply allow a long enough path, and the mask is the
    operator's.

The advisory names parse_path() as the producer and as_path_match() as the
consumer. That is enough to know the class; it is not enough to write a
one-packet trigger without testing.

Next: Part 6 — the smaller failures and protocol edges around the matcher:
extended messages, AS_SETs, attribute lengths, and the limits that are supposed
to bound them.