All of lore.kernel.org
 help / color / mirror / Atom feed
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 2/2] net: tcp: check option lengths in tcp_parse_options()
Date: Tue, 17 Nov 2026 17:56:45 +0900	[thread overview]
Message-ID: <20261117085645.3142669-3-ragaprasanth@gmail.com> (raw)
In-Reply-To: <20261117085645.3142669-1-ragaprasanth@gmail.com>

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


      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 ` [PATCH 1/2] net: tcp: drop segments with an invalid data offset Prasanth R
2026-11-17  8:56 ` Prasanth R [this message]

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-3-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.