* [PATCH nf-next] netfilter: nf_conntrack_tcp: preserve liberal flag in tcp options
@ 2022-03-21 9:42 Pablo Neira Ayuso
2022-03-21 9:44 ` Pablo Neira Ayuso
0 siblings, 1 reply; 4+ messages in thread
From: Pablo Neira Ayuso @ 2022-03-21 9:42 UTC (permalink / raw)
To: netfilter-devel; +Cc: fw, sven.auhagen
When tcp_options is called all flags are cleared.
When the IP_CT_TCP_FLAG_BE_LIBERAL is set it should be preserved
otherwise such connections will fail in the window check.
Signed-off-by: Sven Auhagen <sven.auhagen@voleatech.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
Supersedes: https://patchwork.ozlabs.org/project/netfilter-devel/patch/20220318144939.69465-1-pablo@netfilter.org/ which is not correct, it breaks TCP FIN handling.
net/netfilter/nf_conntrack_proto_tcp.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
index d1582b888c0d..d8599ab5f767 100644
--- a/net/netfilter/nf_conntrack_proto_tcp.c
+++ b/net/netfilter/nf_conntrack_proto_tcp.c
@@ -342,7 +342,7 @@ static void tcp_options(const struct sk_buff *skb,
return;
state->td_scale =
- state->flags = 0;
+ state->flags &= IP_CT_TCP_FLAG_BE_LIBERAL;
while (length > 0) {
int opcode=*ptr++;
@@ -873,7 +873,7 @@ int nf_conntrack_tcp_packet(struct nf_conn *ct,
struct nf_tcp_net *tn = nf_tcp_pernet(net);
struct nf_conntrack_tuple *tuple;
enum tcp_conntrack new_state, old_state;
- unsigned int index, *timeouts;
+ unsigned int index, flags, *timeouts;
enum ip_conntrack_dir dir;
const struct tcphdr *th;
struct tcphdr _tcph;
@@ -968,8 +968,10 @@ 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;
+ flags = ct->proto.tcp.seen[dir].flags;
memset(&ct->proto.tcp.seen[dir], 0,
sizeof(struct ip_ct_tcp_state));
+ ct->proto.tcp.seen[dir].flags = flags & IP_CT_TCP_FLAG_BE_LIBERAL;
break;
}
ct->proto.tcp.last_index = index;
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH nf-next] netfilter: nf_conntrack_tcp: preserve liberal flag in tcp options
2022-03-21 9:42 [PATCH nf-next] netfilter: nf_conntrack_tcp: preserve liberal flag in tcp options Pablo Neira Ayuso
@ 2022-03-21 9:44 ` Pablo Neira Ayuso
2022-03-21 9:46 ` Pablo Neira Ayuso
0 siblings, 1 reply; 4+ messages in thread
From: Pablo Neira Ayuso @ 2022-03-21 9:44 UTC (permalink / raw)
To: netfilter-devel; +Cc: fw, sven.auhagen
On Mon, Mar 21, 2022 at 10:42:05AM +0100, Pablo Neira Ayuso wrote:
> When tcp_options is called all flags are cleared.
> When the IP_CT_TCP_FLAG_BE_LIBERAL is set it should be preserved
> otherwise such connections will fail in the window check.
This patch completes 8437a6209f76 ("netfilter: nft_flow_offload: set liberal tracking mode for tcp")
I'm going to send v2 to add a wrapper function to update these flags,
so we do not accidentally reset IP_CT_TCP_FLAG_BE_LIBERAL.
> Signed-off-by: Sven Auhagen <sven.auhagen@voleatech.de>
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> ---
> Supersedes: https://patchwork.ozlabs.org/project/netfilter-devel/patch/20220318144939.69465-1-pablo@netfilter.org/ which is not correct, it breaks TCP FIN handling.
>
> net/netfilter/nf_conntrack_proto_tcp.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
> index d1582b888c0d..d8599ab5f767 100644
> --- a/net/netfilter/nf_conntrack_proto_tcp.c
> +++ b/net/netfilter/nf_conntrack_proto_tcp.c
> @@ -342,7 +342,7 @@ static void tcp_options(const struct sk_buff *skb,
> return;
>
> state->td_scale =
> - state->flags = 0;
> + state->flags &= IP_CT_TCP_FLAG_BE_LIBERAL;
>
> while (length > 0) {
> int opcode=*ptr++;
> @@ -873,7 +873,7 @@ int nf_conntrack_tcp_packet(struct nf_conn *ct,
> struct nf_tcp_net *tn = nf_tcp_pernet(net);
> struct nf_conntrack_tuple *tuple;
> enum tcp_conntrack new_state, old_state;
> - unsigned int index, *timeouts;
> + unsigned int index, flags, *timeouts;
> enum ip_conntrack_dir dir;
> const struct tcphdr *th;
> struct tcphdr _tcph;
> @@ -968,8 +968,10 @@ 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;
> + flags = ct->proto.tcp.seen[dir].flags;
> memset(&ct->proto.tcp.seen[dir], 0,
> sizeof(struct ip_ct_tcp_state));
> + ct->proto.tcp.seen[dir].flags = flags & IP_CT_TCP_FLAG_BE_LIBERAL;
> break;
> }
> ct->proto.tcp.last_index = index;
> --
> 2.30.2
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH nf-next] netfilter: nf_conntrack_tcp: preserve liberal flag in tcp options
2022-03-21 9:44 ` Pablo Neira Ayuso
@ 2022-03-21 9:46 ` Pablo Neira Ayuso
2022-03-21 10:05 ` Pablo Neira Ayuso
0 siblings, 1 reply; 4+ messages in thread
From: Pablo Neira Ayuso @ 2022-03-21 9:46 UTC (permalink / raw)
To: netfilter-devel; +Cc: fw, sven.auhagen
On Mon, Mar 21, 2022 at 10:44:39AM +0100, Pablo Neira Ayuso wrote:
> On Mon, Mar 21, 2022 at 10:42:05AM +0100, Pablo Neira Ayuso wrote:
> > When tcp_options is called all flags are cleared.
> > When the IP_CT_TCP_FLAG_BE_LIBERAL is set it should be preserved
> > otherwise such connections will fail in the window check.
>
>
> This patch completes 8437a6209f76 ("netfilter: nft_flow_offload: set liberal tracking mode for tcp")
>
> I'm going to send v2 to add a wrapper function to update these flags,
> so we do not accidentally reset IP_CT_TCP_FLAG_BE_LIBERAL.
Hm. Actually I don't see a clear way to add such wrapper function, so
patch LGTM as is.
> > Signed-off-by: Sven Auhagen <sven.auhagen@voleatech.de>
> > Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> > ---
> > Supersedes: https://patchwork.ozlabs.org/project/netfilter-devel/patch/20220318144939.69465-1-pablo@netfilter.org/ which is not correct, it breaks TCP FIN handling.
> >
> > net/netfilter/nf_conntrack_proto_tcp.c | 6 ++++--
> > 1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
> > index d1582b888c0d..d8599ab5f767 100644
> > --- a/net/netfilter/nf_conntrack_proto_tcp.c
> > +++ b/net/netfilter/nf_conntrack_proto_tcp.c
> > @@ -342,7 +342,7 @@ static void tcp_options(const struct sk_buff *skb,
> > return;
> >
> > state->td_scale =
> > - state->flags = 0;
> > + state->flags &= IP_CT_TCP_FLAG_BE_LIBERAL;
> >
> > while (length > 0) {
> > int opcode=*ptr++;
> > @@ -873,7 +873,7 @@ int nf_conntrack_tcp_packet(struct nf_conn *ct,
> > struct nf_tcp_net *tn = nf_tcp_pernet(net);
> > struct nf_conntrack_tuple *tuple;
> > enum tcp_conntrack new_state, old_state;
> > - unsigned int index, *timeouts;
> > + unsigned int index, flags, *timeouts;
> > enum ip_conntrack_dir dir;
> > const struct tcphdr *th;
> > struct tcphdr _tcph;
> > @@ -968,8 +968,10 @@ 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;
> > + flags = ct->proto.tcp.seen[dir].flags;
> > memset(&ct->proto.tcp.seen[dir], 0,
> > sizeof(struct ip_ct_tcp_state));
> > + ct->proto.tcp.seen[dir].flags = flags & IP_CT_TCP_FLAG_BE_LIBERAL;
> > break;
> > }
> > ct->proto.tcp.last_index = index;
> > --
> > 2.30.2
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH nf-next] netfilter: nf_conntrack_tcp: preserve liberal flag in tcp options
2022-03-21 9:46 ` Pablo Neira Ayuso
@ 2022-03-21 10:05 ` Pablo Neira Ayuso
0 siblings, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2022-03-21 10:05 UTC (permalink / raw)
To: netfilter-devel; +Cc: fw, sven.auhagen
[-- Attachment #1: Type: text/plain, Size: 952 bytes --]
On Mon, Mar 21, 2022 at 10:46:36AM +0100, Pablo Neira Ayuso wrote:
> On Mon, Mar 21, 2022 at 10:44:39AM +0100, Pablo Neira Ayuso wrote:
> > On Mon, Mar 21, 2022 at 10:42:05AM +0100, Pablo Neira Ayuso wrote:
> > > When tcp_options is called all flags are cleared.
> > > When the IP_CT_TCP_FLAG_BE_LIBERAL is set it should be preserved
> > > otherwise such connections will fail in the window check.
> >
> >
> > This patch completes 8437a6209f76 ("netfilter: nft_flow_offload: set liberal tracking mode for tcp")
> >
> > I'm going to send v2 to add a wrapper function to update these flags,
> > so we do not accidentally reset IP_CT_TCP_FLAG_BE_LIBERAL.
>
> Hm. Actually I don't see a clear way to add such wrapper function, so
> patch LGTM as is.
Maybe something like this patch that is attached by adding a more
explicit function that resets the window tracking without touch the
liberal flag, it might help to make it more evident to the reader.
[-- Attachment #2: 0001-netfilter-nf_conntrack_tcp-preserve-liberal-flag-in-.patch --]
[-- Type: text/x-diff, Size: 2000 bytes --]
From 4c42d6ca218a9b3da324224a027b753f6acb72c3 Mon Sep 17 00:00:00 2001
From: Pablo Neira Ayuso <pablo@netfilter.org>
Date: Mon, 21 Mar 2022 10:40:07 +0100
Subject: [PATCH] netfilter: nf_conntrack_tcp: preserve liberal flag in tcp
options
When tcp_options is called all flags are cleared.
When the IP_CT_TCP_FLAG_BE_LIBERAL is set it should be preserved
otherwise such connections will fail in the window check.
Signed-off-by: Sven Auhagen <sven.auhagen@voleatech.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_conntrack_proto_tcp.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
index d1582b888c0d..8ec55cd72572 100644
--- a/net/netfilter/nf_conntrack_proto_tcp.c
+++ b/net/netfilter/nf_conntrack_proto_tcp.c
@@ -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++;
@@ -862,6 +862,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,
@@ -968,8 +978,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;
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-03-21 10:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-21 9:42 [PATCH nf-next] netfilter: nf_conntrack_tcp: preserve liberal flag in tcp options Pablo Neira Ayuso
2022-03-21 9:44 ` Pablo Neira Ayuso
2022-03-21 9:46 ` Pablo Neira Ayuso
2022-03-21 10:05 ` Pablo Neira Ayuso
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.