Skip to contentSkip to conversation

tcp: md5: fix potential overestimation of TCP option space

PATCH In review Eric Dumazet 4 participants 4 messages Dec 5, 2019 – Dec 7, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcp: md5: fix potential overestimation of TCP option space

Back in 2008, Adam Langley fixed the corner case of packets for flows having all of the following options : MD5 TS SACK

Since MD5 needs 20 bytes, and TS needs 12 bytes, no sack block can be cooked from the remaining 8 bytes.

tcp_established_options() correctly sets opts->num_sack_blocks to zero, but returns 36 instead of 32.

This means TCP cooks packets with 4 extra bytes at the end of options, containing unitialized bytes.

Fixes 33ad798c924b ("tcp: options clean up")
---
 net/ipv4/tcp_output.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/ipv4/tcp_output.c +3 -2
index be6d22b8190fa375074062032105879270af4be5..b184f03d743715ef4b2d166ceae651529be77953 100644
@@ -755,8 +755,9 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
 			min_t(unsigned int, eff_sacks,
 			      (remaining - TCPOLEN_SACK_BASE_ALIGNED) /
 			      TCPOLEN_SACK_PERBLOCK);
-		size += TCPOLEN_SACK_BASE_ALIGNED +
-			opts->num_sack_blocks * TCPOLEN_SACK_PERBLOCK;
+		if (likely(opts->num_sack_blocks))
+			size += TCPOLEN_SACK_BASE_ALIGNED +
+				opts->num_sack_blocks * TCPOLEN_SACK_PERBLOCK;
 	}
 
 	return size;
Signature · 1 line
2.24.0.393.g34dc348eaf-goog
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Eric Dumazet

Back in 2008, Adam Langley fixed the corner case of packets for flows having all of the following options : MD5 TS SACK

Since MD5 needs 20 bytes, and TS needs 12 bytes, no sack block can be cooked from the remaining 8 bytes.

tcp_established_options() correctly sets opts->num_sack_blocks to zero, but returns 36 instead of 32.

Quoted 7 lines

This means TCP cooks packets with 4 extra bytes at the end of options, containing unitialized bytes.

Fixes 33ad798c924b ("tcp: options clean up")

---

Thanks, Eric!

neal

#2 lore raw
Quoted 15 lines · Neal Cardwell
Quoted 13 lines · Eric Dumazet

Back in 2008, Adam Langley fixed the corner case of packets for flows having all of the following options : MD5 TS SACK

Since MD5 needs 20 bytes, and TS needs 12 bytes, no sack block can be cooked from the remaining 8 bytes.

tcp_established_options() correctly sets opts->num_sack_blocks to zero, but returns 36 instead of 32.

This means TCP cooks packets with 4 extra bytes at the end of options, containing unitialized bytes.

Quoted 6 lines
Quoted 4 lines
Fixes 33ad798c924b ("tcp: options clean up")

---

Thanks for the fix!

Quoted 3 lines

Thanks, Eric!

neal

maintainer
#3 lore raw
In reply to Eric Dumazet

From: Eric Dumazet <[email protected]>
Date: Thu, 5 Dec 2019 10:10:15 -0800

Quoted 9 lines

Back in 2008, Adam Langley fixed the corner case of packets for flows having all of the following options : MD5 TS SACK

Since MD5 needs 20 bytes, and TS needs 12 bytes, no sack block can be cooked from the remaining 8 bytes.

tcp_established_options() correctly sets opts->num_sack_blocks to zero, but returns 36 instead of 32.

Quoted 6 lines

This means TCP cooks packets with 4 extra bytes at the end of options, containing unitialized bytes.

Fixes 33ad798c924b ("tcp: options clean up")

Applied and queued up for -stable, thanks Eric.