All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] net: tcp: fix CVE-2026-29007 and CVE-2026-29008
@ 2026-11-17  8:56 Prasanth R
  2026-11-17  8:56 ` [PATCH 1/2] net: tcp: drop segments with an invalid data offset Prasanth R
  2026-11-17  8:56 ` [PATCH 2/2] net: tcp: check option lengths in tcp_parse_options() Prasanth R
  0 siblings, 2 replies; 3+ messages in thread
From: Prasanth R @ 2026-11-17  8:56 UTC (permalink / raw)
  To: u-boot; +Cc: jerome.forissier, trini, Prasanth R

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(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] net: tcp: drop segments with an invalid data offset
  2026-11-17  8:56 [PATCH 0/2] net: tcp: fix CVE-2026-29007 and CVE-2026-29008 Prasanth R
@ 2026-11-17  8:56 ` Prasanth R
  2026-11-17  8:56 ` [PATCH 2/2] net: tcp: check option lengths in tcp_parse_options() Prasanth R
  1 sibling, 0 replies; 3+ messages in thread
From: Prasanth R @ 2026-11-17  8:56 UTC (permalink / raw)
  To: u-boot; +Cc: jerome.forissier, trini, Prasanth R

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")
Signed-off-by: Prasanth R <prasanth.r@lineo.co.jp>
---
 net/tcp.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/net/tcp.c b/net/tcp.c
index 8740150365f..737a079ec5c 100644
--- a/net/tcp.c
+++ b/net/tcp.c
@@ -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,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] net: tcp: check option lengths in tcp_parse_options()
  2026-11-17  8:56 [PATCH 0/2] net: tcp: fix CVE-2026-29007 and CVE-2026-29008 Prasanth R
  2026-11-17  8:56 ` [PATCH 1/2] net: tcp: drop segments with an invalid data offset Prasanth R
@ 2026-11-17  8:56 ` Prasanth R
  1 sibling, 0 replies; 3+ messages in thread
From: Prasanth R @ 2026-11-17  8:56 UTC (permalink / raw)
  To: u-boot; +Cc: jerome.forissier, trini, 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")
Signed-off-by: Prasanth R <prasanth.r@lineo.co.jp>
---
 net/tcp.c | 42 +++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/net/tcp.c b/net/tcp.c
index 737a079ec5c..cde3319bc4b 100644
--- a/net/tcp.c
+++ b/net/tcp.c
@@ -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;
 	}
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-17 13:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17  8:56 [PATCH 0/2] net: tcp: fix CVE-2026-29007 and CVE-2026-29008 Prasanth R
2026-11-17  8:56 ` [PATCH 1/2] net: tcp: drop segments with an invalid data offset Prasanth R
2026-11-17  8:56 ` [PATCH 2/2] net: tcp: check option lengths in tcp_parse_options() Prasanth R

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.