Skip to contentSkip to conversation

net: tcp: fix CVE-2026-29007 and CVE-2026-29008

PATCH In review Prasanth R 2 participants 4 messages Nov 17 – Nov 23 Networking

lore
Share & tools
lore

Prasanth R

author
#0 lore raw

cover net: tcp: fix CVE-2026-29007 and CVE-2026-29008

The legacy TCP stack trusts the data offset and the option lengths of received segments. A segment whose data offset points past its end makes tcp_parse_options() read beyond the packet (CVE-2026-29007) and makes payload_len negative, which reaches memcpy() as a huge size in TCP_SYN_SENT (CVE-2026-29008). Both were disclosed on this list by VulnCheck in May; as far as I can see they are not fixed yet.

Patch 1 drops segments whose data offset does not fit. Patch 2 makes tcp_parse_options() check each option against the option area, which also fixes a read past the end when the last option byte is TCP_O_END, and limits the window scale to 14.

Testing: ran tcp_parse_options() and the length handling from main and from this series under AddressSanitizer with the malformed segments. Main reads past the packet in all cases; with the series the segments are dropped or the options ignored.
Also built sandbox on current main and ran ut cmd net_test_wget: no failures.

I used an AI assistant (Claude) to help write and test these patches; I reviewed the changes and the results.

Prasanth R (2):
net: tcp: drop segments with an invalid data offset
net: tcp: check option lengths in tcp_parse_options()

 net/tcp.c | 56 +++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 36 insertions(+), 20 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/2 net: tcp: drop segments with an invalid data offset

rxhand_tcp_f() trusts the data offset of a received segment. tcp_rx_state_machine() then passes tcp_hdr_len - TCP_HDR_SIZE bytes of options to tcp_parse_options() and computes payload_len as tcp_len - tcp_hdr_len, without checking that the header fits in the segment.

A data offset larger than the segment makes tcp_parse_options() read past the end of the packet (CVE-2026-29007) and makes payload_len negative. In TCP_SYN_SENT the negative length reaches tcp_rx_user_data() and the receive handler, where it wraps to a huge memcpy() size (CVE-2026-29008).

Drop segments that are shorter than a TCP header, or whose data offset is below the header size or beyond the segment. Also ignore the reserved bits when reading the data offset.

Fixes a3bf193bf4ea ("net: Add TCP protocol")
---
 net/tcp.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
net/tcp.c +13 -1
index 8740150365f..737a079ec5c 100644
@@ -58,7 +58,7 @@ static int (*tcp_stream_on_create)(struct tcp_stream *tcp);
 #define ROUND_TCPHDR_LEN(x) (LEN_B_TO_DW((x) + 3))
 #define ROUND_TCPHDR_BYTES(x) (((x) + 3) & ~3)
 #define SHIFT_TO_TCPHDRLEN_FIELD(x) ((x) << 4)
-#define GET_TCP_HDR_LEN_IN_BYTES(x) ((x) >> 2)
+#define GET_TCP_HDR_LEN_IN_BYTES(x) (((x) & 0xf0) >> 2)
 
 #define RANDOM_PORT_START 1024
 #define RANDOM_PORT_RANGE 0x4000
@@ -1162,6 +1162,18 @@ void rxhand_tcp_f(union tcp_build_pkt *b, unsigned int pkt_len)
 	u16 tcp_rx_xsum = b->ip.hdr.ip_sum;
 	struct tcp_stream *tcp;
 	struct in_addr src;
+	int tcp_hdr_len;
+
+	/*
+	 * The data offset must cover the fixed TCP header and must not point
+	 * past the end of the segment. Otherwise the options parser reads
+	 * beyond the packet and the payload length becomes negative.
+	 */
+	if (tcp_len < (int)TCP_HDR_SIZE)
+		return;
+	tcp_hdr_len = GET_TCP_HDR_LEN_IN_BYTES(b->ip.hdr.tcp_hlen);
+	if (tcp_hdr_len < (int)TCP_HDR_SIZE || tcp_hdr_len > tcp_len)
+		return;
 
 	/* Verify IP header */
 	debug_cond(DEBUG_DEV_PKT,
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/2 net: tcp: check option lengths in tcp_parse_options()

In reply to Prasanth R

tcp_parse_options() reads the length byte of an option without checking that it is inside the option area, and reads the window scale and timestamp values without checking the option length. A truncated or malformed option makes it read past the end of the options.

Check that each option and its length byte fit in the remaining options, and only use the window scale and timestamp when the option has the expected size. Limit the window scale to 14 as RFC 7323 says, so the window shift in tcp_rx_state_machine() stays defined.

Fixes a3bf193bf4ea ("net: Add TCP protocol")
---
 net/tcp.c | 42 +++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)
net/tcp.c +23 -19
index 737a079ec5c..cde3319bc4b 100644
@@ -776,38 +776,42 @@ void tcp_parse_options(struct tcp_stream *tcp, uchar *o, int o_len)
 {
 	struct tcp_t_opt  *tsopt;
 	struct tcp_scale  *wsopt;
+	uchar *end = o + o_len;
 	uchar *p = o;
+	u8 len;
 
-	/*
-	 * NOPs are options with a zero length, and thus are special.
-	 * All other options have length fields.
-	 */
-	for (p = o; p < (o + o_len); ) {
-		if (!p[1])
-			return; /* Finished processing options */
+	while (p < end) {
+		if (p[0] == TCP_O_END)
+			return;
+		if (p[0] == TCP_1_NOP) {
+			p++;
+			continue;
+		}
 
-		switch (p[0]) {
-		case TCP_O_END:
+		/* All other options have a length byte covering kind and len */
+		if (end - p < TCP_OPT_LEN_2)
 			return;
-		case TCP_O_MSS:
-		case TCP_P_SACK:
-		case TCP_V_SACK:
-			break;
+		len = p[1];
+		if (len < TCP_OPT_LEN_2 || len > end - p)
+			return;
+
+		switch (p[0]) {
 		case TCP_O_SCL:
+			if (len != TCP_OPT_LEN_3)
+				break;
 			wsopt = (struct tcp_scale *)p;
-			tcp->rmt_win_scale = wsopt->scale;
+			/* RFC 7323: a shift count above 14 is treated as 14 */
+			tcp->rmt_win_scale = wsopt->scale > 14 ? 14 : wsopt->scale;
 			break;
 		case TCP_O_TS:
+			if (len != TCP_OPT_LEN_A)
+				break;
 			tsopt = (struct tcp_t_opt *)p;
 			tcp->rmt_timestamp = tsopt->t_snd;
 			break;
 		}
 
-		/* Process optional NOPs */
-		if (p[0] == TCP_1_NOP)
-			p++;
-		else
-			p += p[1];
+		p += len;
 	}
 }
 
Signature · 1 line
2.34.1
#3 lore raw
In reply to Prasanth R
Quoted 22 lines

The legacy TCP stack trusts the data offset and the option lengths of received segments. A segment whose data offset points past its end makes tcp_parse_options() read beyond the packet (CVE-2026-29007) and makes payload_len negative, which reaches memcpy() as a huge size in TCP_SYN_SENT (CVE-2026-29008). Both were disclosed on this list by VulnCheck in May; as far as I can see they are not fixed yet.

Patch 1 drops segments whose data offset does not fit. Patch 2 makes tcp_parse_options() check each option against the option area, which also fixes a read past the end when the last option byte is TCP_O_END, and limits the window scale to 14.

Testing: ran tcp_parse_options() and the length handling from main and from this series under AddressSanitizer with the malformed segments. Main reads past the packet in all cases; with the series the segments are dropped or the options ignored.
Also built sandbox on current main and ran ut cmd net_test_wget: no failures.

I used an AI assistant (Claude) to help write and test these patches; I reviewed the changes and the results.

Quoted 6 lines

Prasanth R (2):
net: tcp: drop segments with an invalid data offset
net: tcp: check option lengths in tcp_parse_options()

 net/tcp.c | 56 +++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 36 insertions(+), 20 deletions(-)

Applied to u-boot-net branch for-main [1], thanks!

[1] https://git.u-boot-project.org/u-boot/custodians/u-boot-net/-/commits/for-main

[1/2] net: tcp: drop segments with an invalid data offset

      commit: a0e2935a4bdeb982e48a8f13fa257bbfc6d8e657

[2/2] net: tcp: check option lengths in tcp_parse_options()

      commit: cf248526dbd1da6622b58483c307cb837fb76165

Best regards,

Signature · 1 line
Jerome Forissier <[email protected]>