Skip to content

Commit 71c4a0f

Browse files
edumazetgregkh
authored andcommitted
tcp: fix tcp_mtu_probe() vs highest_sack
[ Upstream commit 2b7cda9c35d3b940eb9ce74b30bbd5eb30db493d ] Based on SNMP values provided by Roman, Yuchung made the observation that some crashes in tcp_sacktag_walk() might be caused by MTU probing. Looking at tcp_mtu_probe(), I found that when a new skb was placed in front of the write queue, we were not updating tcp highest sack. If one skb is freed because all its content was copied to the new skb (for MTU probing), then tp->highest_sack could point to a now freed skb. Bad things would then happen, including infinite loops. This patch renames tcp_highest_sack_combine() and uses it from tcp_mtu_probe() to fix the bug. Note that I also removed one test against tp->sacked_out, since we want to replace tp->highest_sack regardless of whatever condition, since keeping a stale pointer to freed skb is a recipe for disaster. Fixes: a47e5a9 ("[TCP]: Convert highest_sack to sk_buff to allow direct access") Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: Alexei Starovoitov <alexei.starovoitov@gmail.com> Reported-by: Roman Gushchin <guro@fb.com> Reported-by: Oleksandr Natalenko <oleksandr@natalenko.name> Acked-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Neal Cardwell <ncardwell@google.com> Acked-by: Yuchung Cheng <ycheng@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 735818a commit 71c4a0f

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

include/net/tcp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,12 +1612,12 @@ static inline void tcp_highest_sack_reset(struct sock *sk)
16121612
tcp_sk(sk)->highest_sack = tcp_write_queue_head(sk);
16131613
}
16141614

1615-
/* Called when old skb is about to be deleted (to be combined with new skb) */
1616-
static inline void tcp_highest_sack_combine(struct sock *sk,
1615+
/* Called when old skb is about to be deleted and replaced by new skb */
1616+
static inline void tcp_highest_sack_replace(struct sock *sk,
16171617
struct sk_buff *old,
16181618
struct sk_buff *new)
16191619
{
1620-
if (tcp_sk(sk)->sacked_out && (old == tcp_sk(sk)->highest_sack))
1620+
if (old == tcp_highest_sack(sk))
16211621
tcp_sk(sk)->highest_sack = new;
16221622
}
16231623

net/ipv4/tcp_output.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1951,6 +1951,7 @@ static int tcp_mtu_probe(struct sock *sk)
19511951
nskb->ip_summed = skb->ip_summed;
19521952

19531953
tcp_insert_write_queue_before(nskb, skb, sk);
1954+
tcp_highest_sack_replace(sk, skb, nskb);
19541955

19551956
len = 0;
19561957
tcp_for_write_queue_from_safe(skb, next, sk) {
@@ -2464,7 +2465,7 @@ static void tcp_collapse_retrans(struct sock *sk, struct sk_buff *skb)
24642465

24652466
BUG_ON(tcp_skb_pcount(skb) != 1 || tcp_skb_pcount(next_skb) != 1);
24662467

2467-
tcp_highest_sack_combine(sk, next_skb, skb);
2468+
tcp_highest_sack_replace(sk, next_skb, skb);
24682469

24692470
tcp_unlink_write_queue(next_skb, sk);
24702471

0 commit comments

Comments
 (0)