diff mbox series

[RESEND,v3,1/9] net/tcp: fix TCP options processing

Message ID 20240814103145.1347645-2-mikhail.kshevetskiy@iopsys.eu
State Superseded
Delegated to: Ramon Fried
Headers show
Series net: tcp: improve tcp support | expand

Commit Message

Mikhail Kshevetskiy Aug. 14, 2024, 10:31 a.m. UTC
Current TCP code may miss an option if TCP_O_NOP option was used before
it for proper aligning.

Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
---
 net/tcp.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Simon Glass Aug. 17, 2024, 3:58 p.m. UTC | #1
On Wed, 14 Aug 2024 at 04:32, Mikhail Kshevetskiy
<mikhail.kshevetskiy@iopsys.eu> wrote:
>
> Current TCP code may miss an option if TCP_O_NOP option was used before
> it for proper aligning.
>
> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
> ---
>  net/tcp.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>


>
> diff --git a/net/tcp.c b/net/tcp.c
> index b0cc8a1fe3e..3e3118de450 100644
> --- a/net/tcp.c
> +++ b/net/tcp.c
> @@ -475,7 +475,7 @@ void tcp_parse_options(uchar *o, int o_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); p = p + p[1]) {
> +       for (p = o; p < (o + o_len); ) {
>                 if (!p[1])
>                         return; /* Finished processing options */
>
> @@ -490,12 +490,14 @@ void tcp_parse_options(uchar *o, int o_len)
>                 case TCP_O_TS:
>                         tsopt = (struct tcp_t_opt *)p;
>                         rmt_timestamp = tsopt->t_snd;
> -                       return;
> +                       break;
>                 }
>
>                 /* Process optional NOPs */
>                 if (p[0] == TCP_O_NOP)
>                         p++;
> +               else
> +                       p += p[1];
>         }
>  }
>
> --
> 2.39.2
>
diff mbox series

Patch

diff --git a/net/tcp.c b/net/tcp.c
index b0cc8a1fe3e..3e3118de450 100644
--- a/net/tcp.c
+++ b/net/tcp.c
@@ -475,7 +475,7 @@  void tcp_parse_options(uchar *o, int o_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); p = p + p[1]) {
+	for (p = o; p < (o + o_len); ) {
 		if (!p[1])
 			return; /* Finished processing options */
 
@@ -490,12 +490,14 @@  void tcp_parse_options(uchar *o, int o_len)
 		case TCP_O_TS:
 			tsopt = (struct tcp_t_opt *)p;
 			rmt_timestamp = tsopt->t_snd;
-			return;
+			break;
 		}
 
 		/* Process optional NOPs */
 		if (p[0] == TCP_O_NOP)
 			p++;
+		else
+			p += p[1];
 	}
 }