提交 d4e7e61a 编写于 作者: F Florian Westphal 提交者: Xie XiuQi

netfilter: conntrack: always store window size un-scaled

[ Upstream commit 959b69ef57db00cb33e9c4777400ae7183ebddd3 ]

Jakub Jankowski reported following oddity:

After 3 way handshake completes, timeout of new connection is set to
max_retrans (300s) instead of established (5 days).

shortened excerpt from pcap provided:
25.070622 IP (flags [DF], proto TCP (6), length 52)
10.8.5.4.1025 > 10.8.1.2.80: Flags [S], seq 11, win 64240, [wscale 8]
26.070462 IP (flags [DF], proto TCP (6), length 48)
10.8.1.2.80 > 10.8.5.4.1025: Flags [S.], seq 82, ack 12, win 65535, [wscale 3]
27.070449 IP (flags [DF], proto TCP (6), length 40)
10.8.5.4.1025 > 10.8.1.2.80: Flags [.], ack 83, win 512, length 0

Turns out the last_win is of u16 type, but we store the scaled value:
512 << 8 (== 0x20000) becomes 0 window.

The Fixes tag is not correct, as the bug has existed forever, but
without that change all that this causes might cause is to mistake a
window update (to-nonzero-from-zero) for a retransmit.

Fixes: fbcd253d ("netfilter: conntrack: lower timeout to RETRANS seconds if window is 0")
Reported-by: NJakub Jankowski <shasta@toxcorp.com>
Tested-by: NJakub Jankowski <shasta@toxcorp.com>
Signed-off-by: NFlorian Westphal <fw@strlen.de>
Acked-by: NJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 4988c756
...@@ -475,6 +475,7 @@ static bool tcp_in_window(const struct nf_conn *ct, ...@@ -475,6 +475,7 @@ static bool tcp_in_window(const struct nf_conn *ct,
struct ip_ct_tcp_state *receiver = &state->seen[!dir]; struct ip_ct_tcp_state *receiver = &state->seen[!dir];
const struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple; const struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple;
__u32 seq, ack, sack, end, win, swin; __u32 seq, ack, sack, end, win, swin;
u16 win_raw;
s32 receiver_offset; s32 receiver_offset;
bool res, in_recv_win; bool res, in_recv_win;
...@@ -483,7 +484,8 @@ static bool tcp_in_window(const struct nf_conn *ct, ...@@ -483,7 +484,8 @@ static bool tcp_in_window(const struct nf_conn *ct,
*/ */
seq = ntohl(tcph->seq); seq = ntohl(tcph->seq);
ack = sack = ntohl(tcph->ack_seq); ack = sack = ntohl(tcph->ack_seq);
win = ntohs(tcph->window); win_raw = ntohs(tcph->window);
win = win_raw;
end = segment_seq_plus_len(seq, skb->len, dataoff, tcph); end = segment_seq_plus_len(seq, skb->len, dataoff, tcph);
if (receiver->flags & IP_CT_TCP_FLAG_SACK_PERM) if (receiver->flags & IP_CT_TCP_FLAG_SACK_PERM)
...@@ -658,14 +660,14 @@ static bool tcp_in_window(const struct nf_conn *ct, ...@@ -658,14 +660,14 @@ static bool tcp_in_window(const struct nf_conn *ct,
&& state->last_seq == seq && state->last_seq == seq
&& state->last_ack == ack && state->last_ack == ack
&& state->last_end == end && state->last_end == end
&& state->last_win == win) && state->last_win == win_raw)
state->retrans++; state->retrans++;
else { else {
state->last_dir = dir; state->last_dir = dir;
state->last_seq = seq; state->last_seq = seq;
state->last_ack = ack; state->last_ack = ack;
state->last_end = end; state->last_end = end;
state->last_win = win; state->last_win = win_raw;
state->retrans = 0; state->retrans = 0;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册