Threat model

What rawether defends against when it opens raw Ethernet sockets: the ring shared with the kernel, hostile frames, the CAP_NET_RAW privilege, descriptor leaks and silent drops. What it trusts, what is out of scope, and the test that guards each class.

This page summarises rawether’s threat model. The canonical text, with the test behind every claim, is THREAT_MODEL.md. It ships with the crate and is rendered on docs.rs as the rawether::threat_model module. Where they differ, the file is right.

Why a raw-socket library needs one#

A raw socket sits at an unusual point. It holds a privilege that can read and forge any traffic on the link. It shares memory with the kernel. And it hands bytes from an unauthenticated network straight to your code. A bug in any of these is a security bug.

Adversary#

Anyone who can put frames on the link the socket is bound to. Layer 2 has no sender identity: any frame can claim any source address, any EtherType and any VLAN.

Assets#

  • Your process’s memory safety. The receive ring is memory the kernel writes.
  • The raw-socket privilege. Whoever holds it can read and forge traffic on the link.
  • The frames delivered: their bytes, lengths and timestamps.
  • Other hosts’ traffic on the segment.

Trusted#

The kernel and its drivers. Even so, rawether does not let inconsistent ring metadata make it read outside the mapping.

Classes#

IdThreatDefenceStatus
T-01Ring offsets pointing outside the mappingA block is read only once handed over, with acquire ordering. Every offset and length is checked before a slice is formed, and an inconsistent block is skippedmitigated
T-02Using a frame after its memory goes back to the kernelPacket borrows the socket; the next receive releases the block. Enforced by the compilermitigated
T-03Hostile frame shapes: truncated, oversized, crafted tagsVLAN re-insertion, length reporting and the header view p.frame() are total. Wire and captured lengths are separate, truncation is flagged, and a frame too short for its header has no viewmitigated
T-04Frames the filter should have excludedSocket created with protocol 0, filter attached, then bound. Program::new refuses what the kernel refusesmitigated
T-05The privilege kept while parsing untrusted framesdrop_capabilities() clears every capability set, empties the bounding set where it may, sets no_new_privs, and refuses while any other thread still holds a capabilitymitigated (Linux)
T-06The socket inherited by a program you executeEvery descriptor is close-on-execmitigated
T-07Other hosts’ traffic exposed by defaultPromiscuous and all-multicast modes are off unless requestedmitigated
T-08A flood that fills the ring unnoticedBounded ring and buffers; the kernel’s drop counter is readable through stats()detected
T-09Launch-time frames held or dropped silentlysend_at refuses without tx_time; dropped frames are counted by tx_errors()detected
T-10A forged group source address turning a responder into a reply stormFrame::reply refuses to answer a multicast or broadcast sourcemitigated
T-11Earlier frame bytes leaking into the padding of a frame built in a reused bufferFrameBuilder replaces the buffer’s contents and pads with zerosmitigated
T-12The NIC’s device-wide timestamp configuration changed under other programs such as ptp4lRead first, never lowered, never written blindmitigated (Linux)
T-13BPF read-buffer records misparsed (macOS and FreeBSD lay them out differently)Parsed field by field at each platform’s offsets, bounded by the buffermitigated (macOS, FreeBSD)
T-14A control message shorter than what is read from itTruncated buffers ignored; each message checked to hold its payloadmitigated (Linux)
T-15A receive spinning a CPU core when the link goes down or the interface disappearsrecv returns the socket’s errormitigated
T-16A transmit timestamp attributed to the wrong frameEach frame’s id is passed to the kernel (Linux 6.13+); unread timestamps are bounded and their loss countedmitigated (Linux 6.13+)

“Detected” means rawether cannot prevent the loss, but it makes sure you can see it.

Out of scope#

  • Frame authenticity. rawether delivers what arrived. Authenticating it is the protocol’s job: MACsec, IEC 62351-6, PTP authentication TLVs.
  • The user id. drop_capabilities() sheds capabilities, not uid 0. A process started as root keeps root’s file access, so grant CAP_NET_RAW to the binary instead.
  • Frames lost before the socket, in the NIC or the kernel’s per-CPU backlog.
  • Kernel and driver defects, and the accuracy of hardware timestamps.

Deploying safely#

  1. Grant CAP_NET_RAW to the binary (setcap cap_net_raw+ep), or add only that capability to a container. Do not run as root or privileged.
  2. Open every socket, then call drop_capabilities() before spawning threads, building an async runtime or reading the first frame.
  3. Filter on the EtherTypes you use and leave promiscuous mode off, so the kernel discards everything else.
  4. Treat each frame as untrusted input. Read the header through p.frame() rather than indexing, check is_truncated(), and use get(..) rather than [..] when you parse the payload.
  5. Watch stats().dropped, and tx_errors() with launch times, if a lost frame matters.
  6. Fuzz and test your own frame parsers; Frame::new and bpf::Program::run work on plain byte slices.

Reporting a vulnerability#

Report it privately through GitHub’s private vulnerability reporting. Do not open a public issue. Include the OS and version (kernel release or macOS build), the rawether version, the configuration, and the smallest program and frames that show the problem. See the security policy.

Edit this page on GitHub