]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
netfilter: nf_conntrack_tcp: preserve liberal flag in tcp options
authorPablo Neira Ayuso <pablo@netfilter.org>
Mon, 21 Mar 2022 10:38:32 +0000 (11:38 +0100)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 20 May 2022 12:39:34 +0000 (14:39 +0200)
BugLink: https://bugs.launchpad.net/bugs/1969110
[ Upstream commit f2dd495a8d589371289981d5ed33e6873df94ecc ]

Do not reset IP_CT_TCP_FLAG_BE_LIBERAL flag in out-of-sync scenarios
coming before the TCP window tracking, otherwise such connections will
fail in the window check.

Update tcp_options() to leave this flag in place and add a new helper
function to reset the tcp window state.

Based on patch from Sven Auhagen.

Fixes: c4832c7bbc3f ("netfilter: nf_ct_tcp: improve out-of-sync situation in TCP tracking")
Tested-by: Sven Auhagen <sven.auhagen@voleatech.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 6195af5ad80198d43e8ec969d06731db2368c4c3)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
net/netfilter/nf_conntrack_proto_tcp.c

index af5115e127cfd75e09ba8dc9e1bf70719c8dc645..3cee5d8ee70276da81f12773f446f38c03731d99 100644 (file)
@@ -341,8 +341,8 @@ static void tcp_options(const struct sk_buff *skb,
        if (!ptr)
                return;
 
-       state->td_scale =
-       state->flags = 0;
+       state->td_scale = 0;
+       state->flags &= IP_CT_TCP_FLAG_BE_LIBERAL;
 
        while (length > 0) {
                int opcode=*ptr++;
@@ -839,6 +839,16 @@ static bool tcp_can_early_drop(const struct nf_conn *ct)
        return false;
 }
 
+static void nf_ct_tcp_state_reset(struct ip_ct_tcp_state *state)
+{
+       state->td_end           = 0;
+       state->td_maxend        = 0;
+       state->td_maxwin        = 0;
+       state->td_maxack        = 0;
+       state->td_scale         = 0;
+       state->flags            &= IP_CT_TCP_FLAG_BE_LIBERAL;
+}
+
 /* Returns verdict for packet, or -1 for invalid. */
 int nf_conntrack_tcp_packet(struct nf_conn *ct,
                            struct sk_buff *skb,
@@ -945,8 +955,7 @@ int nf_conntrack_tcp_packet(struct nf_conn *ct,
                        ct->proto.tcp.last_flags &= ~IP_CT_EXP_CHALLENGE_ACK;
                        ct->proto.tcp.seen[ct->proto.tcp.last_dir].flags =
                                ct->proto.tcp.last_flags;
-                       memset(&ct->proto.tcp.seen[dir], 0,
-                              sizeof(struct ip_ct_tcp_state));
+                       nf_ct_tcp_state_reset(&ct->proto.tcp.seen[dir]);
                        break;
                }
                ct->proto.tcp.last_index = index;