From: Prasanth R <ragaprasanth@gmail.com>
To: u-boot@lists.denx.de
Cc: jerome.forissier@arm.com, trini@konsulko.com,
Prasanth R <ragaprasanth@gmail.com>
Subject: [PATCH 1/2] net: tcp: drop segments with an invalid data offset
Date: Tue, 17 Nov 2026 17:56:44 +0900 [thread overview]
Message-ID: <20261117085645.3142669-2-ragaprasanth@gmail.com> (raw)
In-Reply-To: <20261117085645.3142669-1-ragaprasanth@gmail.com>
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
next prev parent reply other threads:[~2026-11-17 13:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-11-17 8:56 ` [PATCH 2/2] net: tcp: check option lengths in tcp_parse_options() Prasanth R
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261117085645.3142669-2-ragaprasanth@gmail.com \
--to=ragaprasanth@gmail.com \
--cc=jerome.forissier@arm.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.