[TCP]: Fix NewReno's fast rexmit/recovery problems with GSOed skb

Fixes a long-standing bug which makes NewReno recovery crippled.
With GSO the whole head skb was marked as LOST which is in
violation of NewReno procedure that only wants to mark one packet
and ended up breaking our TCP code by causing counter overflow
because our code was built on top of assumption about valid
NewReno procedure. This manifested as triggering a WARN_ON for
the overflow in a number of places.

It seems relatively safe alternative to just do nothing if
tcp_fragment fails due to oom because another duplicate ACK is
likely to be received soon and the fragmentation will be retried.

Special thanks goes to Soeren Sonnenburg <kernel@nn7.de> who was
lucky enough to be able to reproduce this so that the warning
for the overflow was hit. It's not as easy task as it seems even
if this bug happens quite often because the amount of outstanding
data is pretty significant for the mismarkings to lead to an
overflow.

Because it's very late in 2.6.25-rc cycle (if this even makes in
time), I didn't want to touch anything with SACK enabled here.
Fragmenting might be useful for it as well but it's more or less
a policy decision rather than mandatory fix. Thus there's no need
to rush and we can postpone considering tcp_fragment with SACK
for 2.6.26.

In 2.6.24 and earlier, this very same bug existed but the effect
is slightly different because of a small changes in the if
conditions that fit to the patch's context. With them nothing
got lost marker and thus no retransmissions happened.

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@helsinki.fi>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by Ilpo Järvinen and committed by David S. Miller c137f3dd 1b69d745

+18 -4
+18 -4
net/ipv4/tcp_input.c
··· 2138 2138 { 2139 2139 struct tcp_sock *tp = tcp_sk(sk); 2140 2140 struct sk_buff *skb; 2141 - int cnt; 2141 + int cnt, oldcnt; 2142 + int err; 2143 + unsigned int mss; 2142 2144 2143 2145 BUG_TRAP(packets <= tp->packets_out); 2144 2146 if (tp->lost_skb_hint) { ··· 2159 2157 tp->lost_skb_hint = skb; 2160 2158 tp->lost_cnt_hint = cnt; 2161 2159 2160 + if (after(TCP_SKB_CB(skb)->end_seq, tp->high_seq)) 2161 + break; 2162 + 2163 + oldcnt = cnt; 2162 2164 if (tcp_is_fack(tp) || tcp_is_reno(tp) || 2163 2165 (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_ACKED)) 2164 2166 cnt += tcp_skb_pcount(skb); 2165 2167 2166 - if ((cnt > packets) || 2167 - after(TCP_SKB_CB(skb)->end_seq, tp->high_seq)) 2168 - break; 2168 + if (cnt > packets) { 2169 + if (tcp_is_sack(tp) || (oldcnt >= packets)) 2170 + break; 2171 + 2172 + mss = skb_shinfo(skb)->gso_size; 2173 + err = tcp_fragment(sk, skb, (packets - oldcnt) * mss, mss); 2174 + if (err < 0) 2175 + break; 2176 + cnt = packets; 2177 + } 2178 + 2169 2179 if (!(TCP_SKB_CB(skb)->sacked & (TCPCB_SACKED_ACKED|TCPCB_LOST))) { 2170 2180 TCP_SKB_CB(skb)->sacked |= TCPCB_LOST; 2171 2181 tp->lost_out += tcp_skb_pcount(skb);