In-Kernel Necromancy 2: Sequenced Boogaloo

In-Kernel Necromancy 2: Sequenced Boogaloo

A presentation about a joke SPX implementation for Linux using eBPF.

Find the code here: https://github.com/twisted-pear/ipx_wrap

twisted-pear

November 26, 2026

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

44 slides
  1. Where we were Internetwork Packet eXchange (IPX) is a network-layer

    protocol. Popular in the late 1980s and early 1990s. Removed from the Linux kernel in 2018. https://www.novell.com/documentation/nw6p/?page=/documentation/nw6p/ipx_enu/data/hut0i3h5.html 26.11.2026 eBPF Vienna 3
  2. Where we are Implemented a rudimentary IPX using eBPF and

    some user space helpers. Works by tricking the Linux kernel into believing it is handling IPv6-UDP packets. Thus benefiting from existing IPv6 infrastructure such as addressing, routing, sockets etc. The kernel can route IPX packets. A user space "multiplexer" process can be used to assign IPX addresses to UDP sockets. Applications can use the multiplexer to register their UDP sockets to send and receive IPX packets. We use the TC(X) attachment points and the SCHED_CLS program type. 26.11.2026 eBPF Vienna 4
  3. Where we are | The Trick In Interface Out Interface

    Linux Kernel Routing IPX Header IPv6 Header Dst.: deadbeef.baadcafed00d.face Src.: deadcafe.baadcafec001.face Data Ingress Program Src.: fdaa:bbbb:dead:cafe: baad:caff:fefe:c001 Dst.: fdaa:bbbb:dead:beef: baad:caff:fefe:d00d UDP Header IPX Header Dst.: deadbeef.baadcafed00d.face Egress Program Src.: deadcafe.baadcafec001.face Data Src. Port: 213 Dst. Port: 213 IPX Header Dst.: deadbeef.baadcafed00d.face Src.: deadcafe.baadcafec001.face Data 26.11.2026 eBPF Vienna 5
  4. Where we are | Sequenced Packet eXchange (SPX) Sequenced Packet

    eXchange (SPX): Is a transport protocol built on top of IPX. Guarantees in-order, deduplicated delivery of packets. Uses timeouts, acknowledgement packets and retransmits similarly to TCP. Built an SPX implementation on top of the eBPF IPX implementation. eBPF determines which session an SPX packet belongs to and steers it into the right socket. However eBPF cannot handle retransmits and timeouts, since there is no way to instruct the kernel to send a packet at a later time. Unfortunately eBPF cannot handle acknowledgements since even after a packet is assigned to a socket, there is no guarantee that the packet will actually be delivered. (The receive buffer could be full etc.) Therefore, user space has to periodically call a function to maintain the connection (send retransmits and handle timeouts) and receive packets (to acknowledge them in a timely fashion). 26.11.2026 eBPF Vienna 6
  5. Future Work In-Kernel SPX: This would require additional eBPF capabilities.

    Timeouts and Retransmits: This would require the ability to transmit a packet at some point in the future (and the ability to cancel the transmission). Acknowledgements: This requires a point in the kernel at which the packet is guaranteed to be delivered to user space at which an acknowledgement packet can also be sent. 26.11.2026 eBPF Vienna 8
  6. The Challenge In-Kernel SPX: This would require additional eBPF capabilities.

    Is the above statement really true? Using eBPF: … … Can we get rid of the connection maintenance in user space? … Can we push handling of retransmits, timeouts and acknowledgements into the kernel somehow? … Can we use our previous approach of tricking the kernel into believing it is handling a different protocol again? … And, will it be funny? 26.11.2026 eBPF Vienna 9
  7. What is SPX? | Header Format The IPX header is

    30 bytes long. 1 2 3 Checksum The SPX header is 12 bytes long. Packet Type: Type of service offered or required by the packet. For SPX this is 0x05 . Transport Ctrl. 4 Packet Length Packet Type Destination Network Destination Network Destination Node Connection Control: A bit field for flags related to Destination Socket the packet (ex. "Acknowledgement Required", "End Source Network of Message", "System Packet"). Source Network Source Node Datastream Type: Chosen by the application. Source/Destination Connection ID: The ID that the source/destination of the packet uses to identify the Source Socket Connection Ctrl. Datastream Type Source Connection ID Destination Connection ID Sequence Number Acknowledgement Number Allocation Number connection. Data ... https://www.novell.com/documentation/nw6p/?page=/documentation/nw6p/ipx_enu/data/hc1w6pvi.html#hc1w6pvi 26.11.2026 eBPF Vienna 11
  8. What is SPX? | Header Format Sequence Number: The number

    of the current non- 1 2 3 Checksum system packet the source is sending. Transport Ctrl. Acknowledgement Number: The number of the 4 Packet Length Packet Type Destination Network Destination Network next non-system packet the source expects to Destination Node receive. Destination Socket Allocation Number: The number of slots available Source Network for receiving messages at the source. Source Network Source Node Source Socket Connection Ctrl. Datastream Type Source Connection ID Destination Connection ID Sequence Number Acknowledgement Number Allocation Number Data ... https://www.novell.com/documentation/nw6p/?page=/documentation/nw6p/ipx_enu/data/hc1w6pvi.html#hc1w6pvi 26.11.2026 eBPF Vienna 12
  9. SPX ≈ TCP? | Commonalities Both have sequence numbers. Both

    have retransmissions. Both have acknowledgements. Both use timeouts. Using TCP to emulate SPX seems reasonable at first glance. 26.11.2026 eBPF Vienna 14
  10. SPX ≈ TCP? | The Idea Surely we can trick

    Linux into maintaining an SPX connection by translating between SPX packets and TCP segments in eBPF? The application opens a regular TCP socket. The socket is marked as an SPX socket using a BPF-map. Outgoing TCP segments from that socket are turned into SPX packets. Incoming SPX packets are turned into TCP segments. State-keeping is handled using BPF-maps. 26.11.2026 eBPF Vienna 15
  11. SPX ≈ TCP? | Differences TCP sequence and acknowledgement numbers

    track bytes. SPX sequence and acknowledgement numbers track packets. No problem, we can translate between those in eBPF! Different space for sequence numbers. 4 bytes with TCP, 2 bytes with SPX. No problem, we can keep offsets and manage overflows in eBPF! TCP has a 3-way handshake. SPX has a 2-way handshake. No problem, we can synthesize the final ACK-segment of the 3-way handshake in eBPF! TCP has stream semantics. SPX has message semantics. 26.11.2026 eBPF Vienna 17
  12. SPX ≈ TCP? | Differences TCP has stream semantics. SPX

    has message semantics. Protocol Sender Receiver SPX send(A)|send(B)|send(C) recv(A)|recv(B)|recv(C) send(A)|send(B)|send(C) recv(A)|recv(B)|recv(C) or recv(AB)|recv(C) or recv(A)|recv(BC) or recv(ABC) TCP Even if each SPX packet is turned into its own TCP segment, there is no guarantee that the receiver’s kernel does not simply merge segments after reception! And no, tricks with the TCP urgent pointer or the "Kernel Connection Multiplexer" (KCM) do, in fact, not work! 26.11.2026 eBPF Vienna 18
  13. SPX ≉ TCP! | Alternatives Ok, so translating between SPX

    and TCP using just eBPF does not seem possible. What can we do? Add a framing header into each TCP segment that indicates the length of the data for the next receive: There is no way in eBPF to remove the framing header before data is delivered to the application. The application would have to strip out the framing header itself. The whole point of the exercise was that the application could just write to or receive from the socket without having to manage the transport protocol. Unacceptable! Find a different transport protocol: The Linux kernel needs to support it natively. We need to be able to translate between it and SPX in eBPF. It needs to preserve message boundaries when sending and receiving. 26.11.2026 eBPF Vienna 20
  14. SCTP | Overview The Stream Control Transmission Protocol (SCTP) provides

    reliable, ordered transport of messages. SCTP is supported by the Linux kernel. An SCTP packet consists of a common SCTP header and one or more chunks. Chunks have a header and can either deliver data or control information. SCTP sequence and acknowledgement numbers track chunks. Transmission sequence numbers (TSNs) are 4 bytes long. SCTP has a 4-way handshake. This helps to prevent resource exhaustion attacks. SCTP has message semantics! 26.11.2026 eBPF Vienna 22
  15. SCTP | Header Format The common header is 12 bytes

    long. 1 2 3 Source Port A chunk is at least 4 bytes long. 4 Destination Port Verification Tag Verification Tag: A random value set during Checksum connection establishment. Supposed to make off- Chunk #1 Type path attacks more difficult. Chunk #1 Flags Chunk #1 Length Chunk #1 Value Checksum: The CRC32c checksum of the SCTP ... header and all chunks. Chunk #2 Type Chunk Type: Indicates the type of chunk (ex. DATA). Chunk #2 Flags Chunk #2 Length Chunk #2 Value ... Chunk Flags: Type-specific flags. Chunk #3 Chunk Length: Length of the chunk including the ... chunk header and excluding the chunk padding. ... (Chunks are padded to a multiple of 4 bytes.) 26.11.2026 eBPF Vienna 23
  16. SCTP | DATA Chunk The DATA chunk transmits user data.

    Transmission Sequence Number (TSN): Used to 1 2 Chunk Type Chunk Flags 3 4 Chunk Length Transmission Sequence Number (TSN) order DATA chunks. Stream ID & Stream Sequence Number: SCTP can transport multiple parallel streams of data. We Stream ID Stream Sequence Number Payload Protocol Identifier Data won’t be using this. ... Payload Protocol Identifier: This value can be set by the sending application. We use it to encode the SPX datastream type and flags. 26.11.2026 eBPF Vienna 24
  17. SCTP | SACK Chunk The Selective Acknowledgement (SACK) chunk acknowledges

    DATA chunks. 1 2 Chunk Type Chunk Flags chunks were received. 4 Chunk Length Cumulative TSN Ack Cumulative TSN Ack: The TSN of the last DATA chunk, where that chunk itself and all previous 3 Advertised Receiver Window Credit Number of Gap Ack Blocks (N) Number of Duplicate TSNs (M) Gap Ack Block #1 We don’t really care about the rest of the fields. Gap Ack Block #2 ... Gap Ack Block #N Duplicate TSN #1 Duplicate TSN #2 ... Duplicate TSN #M 26.11.2026 eBPF Vienna 25
  18. Implementation | Overview Conceptually we want something like this: Application

    Linux Kernel SCTP socket API IPX/SPX Machine eBPF SCTP packets SPX packets The Linux kernel’s SCTP implementation handles sockets, timeouts, retransmits and acknowledgements. We just translate the packets between SPX and SCTP using eBPF. The kernel is left unchanged. The entire implementation is either in eBPF or in user space. 26.11.2026 eBPF Vienna 27
  19. Implementation | Overview However: Connections can be incoming ( accept()

    ) or outgoing ( connect() ). SPX and SCTP both need to establish a connection and the handshake is very different. SCTP can deliver multiple chunks with different meanings in one packet. One SCTP packet does not cleanly translate into one SPX packet and vice-versa. 26.11.2026 eBPF Vienna 28
  20. Implementation | Ingress 1. Connection Dispatch: Each SPX packet is

    dispatched to a connection using the IPX addresses and the Destination Connection ID field of the SPX packet. (Except for connection requests, which have to be handled separately.) 2. State Program: The eBPF ingress program for the current state of the connection is called. 3. Admission Function: The SPX packet is either accepted or rejected by the state. 4. Update Function: If the SPX packet is accepted, the state variables are updated. 5. Transformation Function: If the SPX packet is accepted, it is transformed into an SCTP packet. 6. Ingress: The new SCTP packet is sent on to the kernel’s network stack where it is handled by the appropriate SCTP association. 26.11.2026 eBPF Vienna 29
  21. Implementation | Egress 1. Connection Dispatch: Each SCTP packet is

    dispatched to a connection using the socket that generated it. 2. "Flattening": If the SCTP packet has multiple chunks, it is split up into multiple packets, such that each one contains only one chunk. These one-chunk packets are reinjected into the egress path and go through step 1 again. If the packet only has one chunk it goes on to step 3. 3. State Program: The eBPF egress program for the current state of the connection is called. 4. Admission Function: The SCTP packet is either accepted or rejected by the state. 5. Update Function: If the SCTP packet is accepted, the state variables are updated. 6. Transformation Function: If the SCTP packet is accepted, it is transformed into an SPX packet. 7. Egress: The new SPX packet is sent out the interface. 26.11.2026 eBPF Vienna 30
  22. Implementation | Outgoing Connections Application SCTP socket API SCTP packets

    Linux Kernel SPX packets eBPF IPX/SPX Machine State: NEW connect() INIT Chunk INIT-ACK Chunk Connection Request Connection Ack State: CONN_ACK_RCVD Socket Lifetime COOKIE-ECHO Chunk SPX Connection SCTP Association COOKIE-ACK Chunk State: ESTABLISHED 26.11.2026 eBPF Vienna 31
  23. Implementation | Incoming Connections Application SCTP socket API SCTP packets

    Linux Kernel SPX packets eBPF IPX/SPX Machine Connection Request State: INCOMING connect() INIT Chunk Connection Ack INIT-ACK Chunk State: CONN_ACK_SENT COOKIE-ECHO Chunk Socket Lifetime SPX Connection COOKIE-ACK Chunk State: PRE_ESTABLISHED SCTP Association DATA/SACK Chunk Not a Connection Request State: ESTABLISHED 26.11.2026 eBPF Vienna 32
  24. Implementation | Sending Data Application SCTP socket API SCTP packets

    Linux Kernel send() Socket Lifetime SCTP Association SPX packets eBPF DATA Chunk [TSN = X] DATA Chunk [TSN = X] send() SACK Chunk [ACK = X] DATA Chunk [TSN = X + 1] 26.11.2026 eBPF Vienna IPX/SPX Machine SPX Data [SEQ = f(X)] State: ESTABLISHED SPX Connection SPX Data [SEQ = f(X)] SPX Ack [ACK = f(X) + 1] SPX Data [SEQ = f(X + 1)] 33
  25. Implementation | Receiving Data Application SCTP socket API SCTP packets

    Linux Kernel SPX packets eBPF DATA Chunk [TSN = g(X)] SACK Chunk [ACK = g(X)] IPX/SPX Machine SPX Data [SEQ = X] SPX Ack [ACK = X + 1] recv() Socket Lifetime SCTP Association State: ESTABLISHED DATA Chunk [TSN = g(X)] SACK Chunk [ACK = g(X)] recv() 26.11.2026 DATA Chunk [TSN = g(X + 1)] eBPF Vienna SPX Connection SPX Data [SEQ = X] SPX Ack [ACK = X + 1] SPX Data [SEQ = X + 1] 34
  26. Implementation | Shutdown & Abort SCTP connection abort: If SCTP

    generates an ABORT chunk, the connection state is immediately removed. SPX peer shuts down connection: 1. The ingress eBPF program generates a SHUTDOWN chunk. 2. The connection moves into the SHUTDOWN_RCVD state. 3. Once SCTP sends a SHUTDOWN-ACK chunk, we acknowledge the end of the connection via SPX. 4. The connection state is removed. Application shuts down connection: 1. SCTP generates a SHUTDOWN chunk. 2. The egress eBPF program generates an SPX packet signaling the end of the connection to the peer. 3. The connection moves into the SHUTDOWN_SENT state. 4. Once the SPX peer acknowledges, the ingress eBPF program generates a SHUTDOWN-ACK chunk. 5. Once SCTP sends a SHUTDOWN-COMPLETE chunk, the connection state is removed. 26.11.2026 eBPF Vienna 35
  27. Implementation | Pitfalls Sequence number ↔ TSN conversion: SPX sequence

    numbers have 16 bits. SCTP TSNs have 32 bits. The conversion needs to account for integer overflows. Retransmits of Connection Requests: Since SPX connection requests do not contain the local connection ID, they need to be handled specially. Otherwise each retransmit (due to a lost connection ack) would create a new connection. Checksums: We need to calculate the SCTP checksum when transforming incoming packets in eBPF. Heartbeats: If SCTP HEARTBEAT chunks remain unacknowledged, the association is terminated by the kernel. Hence, we need to inject an additional HEARTBEAT-ACK chunk into incoming packets whenever a heartbeat is waiting for an acknowledgement. SCTP sockets & BPF-maps: SCTP sockets cannot be stored in BPF-maps. We cannot use bpf_sk_assign() . 26.11.2026 eBPF Vienna 36
  28. Implementation | Pitfalls Looking up SCTP sockets: There is no

    bpf_sk_lookup_sctp() . If we want to look up SCTP sockets, we need to track them ourselves. SKB CB field: We use this field to track packets that need to be reinjected into the ingress or egress path. We need this when splitting up SCTP packets into individual chunks or when we reflect SCTP packets back. This breaks horribly if another TC(X) program were to use it. SCTP timeouts: The timeout and retransmit behavior of SCTP is not identical to SPX. Though we can make it match more closely with some socket options. Peeking at message lengths: With UDP we could use the MSG_TRUNC|MSG_PEEK flag combination. This does not work with SCTP. Instead, to get the length of the next message before receiving it we need to enable the SCTP_RECVNXTINFO socket option and then retrieve the length from the ancillary message data with recvmsg() . The eBPF verifier: is cumbersome. 26.11.2026 eBPF Vienna 37
  29. Demo | Network Container 4 .00addead0104 Container 1 Container 2

    .00addead0101 .00addead0301 Host .82d6f3dd9717 .00addead0202 00000001 Net 1 .525400123456 00000003 Net 3 .00addead0102 IPXTST01 .00addead0203 .00addead0503 00000002 Net 2 .525400123457 .000000000001 .525400123458 00000004 Net 4 012bc42c Internal IPXTST01 26.11.2026 Container 3 IPXTST02 .525400123459 .000000000001 00000005 Net 5 08244ace Internal IPXTST02 eBPF Vienna 39
  30. My Experience Wrapping individual IPX packets into IPv6-UDP packets and

    having them routed and dispatched to sockets is comparatively easy. Translating a connection-oriented transport protocol is much more involved and error-prone. The attempt using TCP was a huge waste of time. I was working against almost half a century of engineering designed to make TCP behave as a stream of bytes. This was fun but definitely difficult. 26.11.2026 eBPF Vienna 41
  31. Future Work SPX II: Right now only SPX I is

    supported. Generalization: Can the approach taken here be generalized to other protocols? Which ones? Which properties are needed? What is the minimal set of eBPF capabilities required? 26.11.2026 eBPF Vienna 43

More Decks by twisted-pear

Other Decks in Programming