Curiosity helped me to learn something interesting - write() returned 1000000 bytes sent. The server got 573408 bytes only. Multiple runs on my LAN, different numbers each run - and of course none of them indicating successful delivery of what was written :). I didn’t know that TCP could do that until I read Bert Hubert’s old post about SO_LINGER, which I found through Tsoding’s stream.
After discovering this, it didn’t take long to figure out that this is not something new, and that’s not an edge case for Linux, it has quite old roots:
- The RFC specification: RFC 1122 (§ 4.2.2.13, 1989) says that closing a socket while received data remains pending in TCP buffers - or receiving new segments after CLOSE - should trigger a TCP RST to signal unread data loss.
- The classic reference: W. Richard Stevens covered
close()vsshutdown()and SO_LINGER in detail in the 1990s in UNIX Network Programming, Vol. 1.
Losing data over TCP
The server sends a welcome line. The client never reads it, writes 1 MB and closes.
#include <arpa/inet.h>
#include <stdio.h>
#include <unistd.h>
#define SEND_WELCOME 1 /* 1 = reproduce the data loss, 0 = no unread data on the client */
int main(void)
{
int ls = socket(AF_INET, SOCK_STREAM, 0);
int one = 1;
setsockopt(ls, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
struct sockaddr_in addr = {0};
addr.sin_family = AF_INET;
addr.sin_port = htons(6969);
addr.sin_addr.s_addr = htonl(INADDR_ANY);
bind(ls, (struct sockaddr *)&addr, sizeof(addr));
listen(ls, 16);
int c = accept(ls, NULL, NULL);
if (SEND_WELCOME)
send(c, "220 Welcome\r\n", 13, 0); /* the client never reads this */
sleep(1); /* slow reader, data piles up */
char buf[4096];
long total = 0;
ssize_t n;
while ((n = read(c, buf, sizeof(buf))) > 0)
total += n;
if (n < 0)
perror("read");
printf("received %ld bytes\n", total);
close(c);
close(ls);
return 0;
}
#include <arpa/inet.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#define SERVER "127.0.0.1" /* change to your server */
#define CLEAN_CLOSE 0 /* 0 = naive close(), 1 = shutdown() + drain + close() */
static char buf[1000000];
int main(void)
{
int s = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in dst = {0};
dst.sin_family = AF_INET;
dst.sin_port = htons(6969);
inet_pton(AF_INET, SERVER, &dst.sin_addr);
connect(s, (struct sockaddr *)&dst, sizeof(dst));
memset(buf, 'a', sizeof(buf));
printf("write() returned %zd\n", write(s, buf, sizeof(buf)));
if (CLEAN_CLOSE) {
shutdown(s, SHUT_WR); /* FIN after all queued data */
char tmp[4096];
while (read(s, tmp, sizeof(tmp)) > 0)
; /* drain until the server closes */
}
close(s);
return 0;
}
Client and server are in the same LAN:
naive close(): 573408, 550240, 501008, 970160, 615456 bytes, then "Connection reset by peer"
CLEAN_CLOSE 1: 1000000, 1000000
close() ends up in tcp_close(). It finds the unread welcome line in the receive queue and, as RFC 1122 asks, sends a RST instead of a FIN. Whatever is still in the send queue is gone. write() returned long before that, it only copied the data into the kernel. How much reached the server by then depends on timing, so the numbers jump around.
The client kernel counts these:
nstat -n; ./tcp_client; nstat TcpExtTCPAbortOnClose
SO_LINGER changes nothing here, the reset still happens. What works is the CLEAN_CLOSE branch: shutdown(SHUT_WR), read until 0, then close(). Apache and nginx have done this for years under the name “lingering close”.
Where it happens
I modified a bit the path from a TUM paper, The Path of a Packet Through the Linux Kernel, with the calls that are relevant for this post.
tcp_sendmsg() copies into the send queue and returns. That’s the write() above. tcp_write_xmit() sends later, when the windows allow it. On the way in, ip_rcv() runs PREROUTING, ip_rcv_finish() parses IP options and looks up the route, tcp_v4_rcv() finds the socket. Handshake packets go to tcp_check_req(), data goes into the receive queue. That’s where the welcome line sat until close() found it.
Worth remembering: tcpdump gets incoming packets before netfilter sees them.
CVE-2026-98432
A fresh bug on the same path, CVE-2026-98432.
If a SYN carries IP options, the server keeps a copy in the request socket, ireq_opt, to echo it in the SYN-ACK. When the handshake completes, tcp_v4_syn_recv_sock() gives that buffer to the child socket without copying it. A retransmitted SYN handled on another CPU can still be building a SYN-ACK from it in ip_options_build(), while the child is already closed and inet_sock_destruct() freed the buffer with kfree(). Use after free.
The bug is old, since 4.4. The fix is kfree_rcu() in two places. Fixed in 7.3 and in stable 5.10.272, 5.15.223, 6.1.190, 6.6.159, 6.12.113, 6.18.56 and 7.2.10. CVSS 9.8 in the record, Ubuntu grades CVE as High, Red Hat as moderate. You need an open TCP port, a SYN with IP options and a won race. At the current point (29 Oct 2026) upstream is fixed, but Ubuntu has no fixed kernel yet.
IP options barely exist in real traffic, most networks drop them (RFC 7126). Record Route is the easy one to play with, ping -R uses it.
Watching the options get stored
This client sends one SYN with Record Route. A single connection won’t hit the race, it just makes the buffer from the CVE visible + allows us testing the nftables drop rule.
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <stdio.h>
#include <sys/socket.h>
#include <unistd.h>
#define SERVER "127.0.0.1" /* change to your server */
#define USE_OPTIONS 1 /* 1 = SYN carries IPv4 Record Route, 0 = plain SYN */
int main(void)
{
int s = socket(AF_INET, SOCK_STREAM, 0);
if (USE_OPTIONS) {
/* Record Route: type 7, length 7, pointer 4, one empty slot, then EOL */
unsigned char rr[8] = { 7, 7, 4, 0, 0, 0, 0, 0 };
setsockopt(s, IPPROTO_IP, IP_OPTIONS, rr, sizeof(rr));
}
int syncnt = 1; /* give up after ~3 s instead of ~2 min */
setsockopt(s, IPPROTO_TCP, TCP_SYNCNT, &syncnt, sizeof(syncnt));
struct sockaddr_in dst = {0};
dst.sin_family = AF_INET;
dst.sin_port = htons(6969);
inet_pton(AF_INET, SERVER, &dst.sin_addr);
if (connect(s, (struct sockaddr *)&dst, sizeof(dst)) == 0)
printf("connected (options %s)\n", USE_OPTIONS ? "on" : "off");
else
perror("connect");
close(s);
return 0;
}
client -> server [S] opts=[7, 7, 8, 127, 0, 0, 1, 0]
server -> client [S.] opts=[7, 7, 8, 127, 0, 0, 1, 0]
server -> client [P.] opts=[7, 7, 8, 127, 0, 0, 1, 0]
The SYN-ACK echoes the option, that’s ireq_opt. The welcome line from the server still carries it after the handshake, so the child socket uses the same buffer. Those are the two owners from the CVE.
Blocking them until the patch
There’s no official mitigation. net.ipv4.tcp_migrate_req=0 gets mentioned, but it’s the default and covers only the rarer path. No IP options in the SYN means nothing gets stored, so I drop TCP with IP options before the kernel parses them:
nft add table inet cve98432
nft add chain inet cve98432 pre '{ type filter hook prerouting priority raw; policy accept; }'
nft add rule inet cve98432 pre ip hdrlength != 5 meta l4proto tcp counter drop
On the box initiating the socket:
no rule: connected (options on)
rule loaded: connect: Connection timed out
rule deleted: connected (options on)
The counter after one blocked attempt said 3 packets, 204 bytes. 68 bytes each: 28 bytes IP header with the option, 40 bytes TCP. A normal SYN is 60 and passes.
And the capture on the box with the rule loaded:
xxx.36370 > yyy.6969: Flags [S], seq 2523505216, win 64240, options [mss 1460,sackOK,TS val 549084329 ecr 0,nop,wscale 10], length 0
xxx.36370 > yyy.6969: Flags [S], seq 2523505216, win 64240, options [mss 1460,sackOK,TS val 549085362 ecr 0,nop,wscale 10], length 0
xxx.36370 > yyy.6969: Flags [S], seq 2523505216, win 64240, options [mss 1460,sackOK,TS val 549086386 ecr 0,nop,wscale 10], length 0
The SYNs arrive, no SYN-ACK goes back. tcpdump copies them in __netif_receive_skb_core(), the rule drops them a bit later in ip_rcv(). So seeing a packet in a capture doesn’t mean the box accepted it.
This isn’t an official fix, just a potential way of working around it until the patch comes live, without breaking anything (normally we should not rely on these options).