Skip to contentSkip to conversation

tcp: fix possible crash in tcp_v4_err()

PATCH In review Eric Dumazet 5 participants 9 messages Feb 15, 2019 – Feb 18, 2019

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

cover tcp: fix possible crash in tcp_v4_err()

soukjin bae reported a crash in tcp_v4_err() that we root caused to a missing initialization.

Second patch adds a sanity check in tcp_v4_err() to avoid future potential problems. Ignoring an ICMP message is probably better than crashing a machine.

Eric Dumazet (2):
tcp: clear icsk_backoff in tcp_write_queue_purge()
tcp: tcp_v4_err() should be more careful

 net/ipv4/tcp.c      | 2 +-
 net/ipv4/tcp_ipv4.c | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
#1 lore raw

PATCH 1/2 tcp: clear icsk_backoff in tcp_write_queue_purge()

soukjin bae reported a crash in tcp_v4_err() handling ICMP_DEST_UNREACH after tcp_write_queue_head(sk) returned a NULL pointer.

Current logic should have prevented this :

  if (seq != tp->snd_una  || !icsk->icsk_retransmits ||
      !icsk->icsk_backoff || fastopen)
      break;

Problem is the write queue might have been purged
and icsk_backoff has not been cleared.

---
 net/ipv4/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp.c +1 -1
index 2079145a3b7c5f498af429c9a8289342e4421fca..cf3c5095c10e8e7e56621beae2f93c93de184489 100644
@@ -2528,6 +2528,7 @@ void tcp_write_queue_purge(struct sock *sk)
 	sk_mem_reclaim(sk);
 	tcp_clear_all_retrans_hints(tcp_sk(sk));
 	tcp_sk(sk)->packets_out = 0;
+	inet_csk(sk)->icsk_backoff = 0;
 }
 
 int tcp_disconnect(struct sock *sk, int flags)
@@ -2576,7 +2577,6 @@ int tcp_disconnect(struct sock *sk, int flags)
 	tp->write_seq += tp->max_window + 2;
 	if (tp->write_seq == 0)
 		tp->write_seq = 1;
-	icsk->icsk_backoff = 0;
 	tp->snd_cwnd = 2;
 	icsk->icsk_probes_out = 0;
 	tp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
maintainer Acked-by on v1 1/2
#2 lore raw

Re: [PATCH net 1/2] tcp: clear icsk_backoff in tcp_write_queue_purge()

Quoted 11 lines · Eric Dumazet

soukjin bae reported a crash in tcp_v4_err() handling ICMP_DEST_UNREACH after tcp_write_queue_head(sk) returned a NULL pointer.

Current logic should have prevented this :

  if (seq != tp->snd_una  || !icsk->icsk_retransmits ||
      !icsk->icsk_backoff || fastopen)
      break;
Quoted 8 lines

Problem is the write queue might have been purged
and icsk_backoff has not been cleared.

---
 net/ipv4/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Thanks!

neal

#3 lore raw

PATCH 2/2 tcp: tcp_v4_err() should be more careful

In reply to Eric Dumazet

ICMP handlers are not very often stressed, we should make them more resilient to bugs that might surface in the future.

If there is no packet in retransmit queue, we should avoid a NULL deref.

---
 net/ipv4/tcp_ipv4.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/tcp_ipv4.c +4 -1
index efc6fef692ffdca4dcdd3f4b87a837656dd66c8c..ec3cea9d68288244d8e03b655d06f91640c36ee7 100644
@@ -536,12 +536,15 @@ int tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
 		if (sock_owned_by_user(sk))
 			break;
 
+		skb = tcp_rtx_queue_head(sk);
+		if (WARN_ON_ONCE(!skb))
+			break;
+
 		icsk->icsk_backoff--;
 		icsk->icsk_rto = tp->srtt_us ? __tcp_set_rto(tp) :
 					       TCP_TIMEOUT_INIT;
 		icsk->icsk_rto = inet_csk_rto_backoff(icsk, TCP_RTO_MAX);
 
-		skb = tcp_rtx_queue_head(sk);
 
 		tcp_mstamp_refresh(tp);
 		delta_us = (u32)(tp->tcp_mstamp - tcp_skb_timestamp_us(skb));
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
maintainer Acked-by on v1 2/2
#4 lore raw

Re: [PATCH net 2/2] tcp: tcp_v4_err() should be more careful

Quoted 5 lines · Eric Dumazet

ICMP handlers are not very often stressed, we should make them more resilient to bugs that might surface in the future.

Quoted 8 lines

If there is no packet in retransmit queue, we should avoid a NULL deref.

---
 net/ipv4/tcp_ipv4.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Thanks!

neal

#5 lore raw

Re: [PATCH net 2/2] tcp: tcp_v4_err() should be more careful

Quoted 10 lines · Neal Cardwell
Quoted 8 lines · Eric Dumazet

ICMP handlers are not very often stressed, we should make them more resilient to bugs that might surface in the future.

If there is no packet in retransmit queue, we should avoid a NULL deref.

Quoted 7 lines
Quoted 5 lines
---
 net/ipv4/tcp_ipv4.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Thanks you for the fix, Eric!

Quoted 4 lines

Thanks!

neal

maintainer
#6 lore raw
In reply to Eric Dumazet

From: Eric Dumazet <[email protected]>
Date: Fri, 15 Feb 2019 13:36:19 -0800

Quoted 6 lines

soukjin bae reported a crash in tcp_v4_err() that we root caused to a missing initialization.

Second patch adds a sanity check in tcp_v4_err() to avoid future potential problems. Ignoring an ICMP message is probably better than crashing a machine.

Series applied, thanks Eric.

Want me to queue these up for -stable?

#7 lore raw
Quoted 6 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Fri, 15 Feb 2019 13:36:19 -0800

Quoted 3 lines

soukjin bae reported a crash in tcp_v4_err() that we root caused to a missing initialization.

Quoted 8 lines
Quoted 3 lines

Second patch adds a sanity check in tcp_v4_err() to avoid future potential problems. Ignoring an ICMP message is probably better than crashing a machine.

Series applied, thanks Eric.

Want me to queue these up for -stable?

Yes please, I put no Fixes: tag because it seemed to be a day-0 bug.

Thanks !

maintainer
#8 lore raw

From: Eric Dumazet <[email protected]>
Date: Sun, 17 Feb 2019 18:20:21 -0800

Quoted 13 lines · David Miller
Quoted 10 lines

From: Eric Dumazet <[email protected]>
Date: Fri, 15 Feb 2019 13:36:19 -0800

Quoted 6 lines

soukjin bae reported a crash in tcp_v4_err() that we root caused to a missing initialization.

Second patch adds a sanity check in tcp_v4_err() to avoid future potential problems. Ignoring an ICMP message is probably better than crashing a machine.

Quoted 6 lines
Quoted 4 lines

Series applied, thanks Eric.

Want me to queue these up for -stable?

Yes please, I put no Fixes: tag because it seemed to be a day-0 bug.

Done.