Skip to contentSkip to conversation

tcp: Reset bytes_acked and bytes_received when disconnecting

PATCH In review Christoph Paasch 3 participants 3 messages Jul 7, 2019 – Jul 9, 2019

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

PATCH 1/1 tcp: Reset bytes_acked and bytes_received when disconnecting

If an app is playing tricks to reuse a socket via tcp_disconnect(), bytes_acked/received needs to be reset to 0. Otherwise tcp_info will report the sum of the current and the old connection..

Cc Eric Dumazet <[email protected]>
Fixes 0df48c26d841 ("tcp: add tcpi_bytes_acked to tcp_info")
Fixes bdd1f9edacb5 ("tcp: add tcpi_bytes_received to tcp_info")
---
 net/ipv4/tcp.c | 2 ++
 1 file changed, 2 insertions(+)
net/ipv4/tcp.c +2 -0
index 7dc9ab84bb69..2eebd092c3c1 100644
@@ -2614,6 +2614,8 @@ int tcp_disconnect(struct sock *sk, int flags)
 	tcp_saved_syn_free(tp);
 	tp->compressed_ack = 0;
 	tp->bytes_sent = 0;
+	tp->bytes_acked = 0;
+	tp->bytes_received = 0;
 	tp->bytes_retrans = 0;
 	tp->duplicate_sack[0].start_seq = 0;
 	tp->duplicate_sack[0].end_seq = 0;
Signature · 1 line
2.21.0
#1 lore raw
Quoted 10 lines · Christoph Paasch

If an app is playing tricks to reuse a socket via tcp_disconnect(), bytes_acked/received needs to be reset to 0. Otherwise tcp_info will report the sum of the current and the old connection..

Cc Eric Dumazet <[email protected]>
Fixes 0df48c26d841 ("tcp: add tcpi_bytes_acked to tcp_info")
Fixes bdd1f9edacb5 ("tcp: add tcpi_bytes_received to tcp_info")

---

I am sure other fields miss their zeroing as well.

maintainer
#2 lore raw
In reply to Christoph Paasch

From: Christoph Paasch <[email protected]>
Date: Sat, 06 Jul 2019 16:13:07 -0700

Quoted 8 lines

If an app is playing tricks to reuse a socket via tcp_disconnect(), bytes_acked/received needs to be reset to 0. Otherwise tcp_info will report the sum of the current and the old connection..

Cc Eric Dumazet <[email protected]>
Fixes 0df48c26d841 ("tcp: add tcpi_bytes_acked to tcp_info")
Fixes bdd1f9edacb5 ("tcp: add tcpi_bytes_received to tcp_info")

Applied and queued up for -stable.