[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <acba99bf-975d-54d8-01cf-938d2579f06e@nvidia.com>
Date: Mon, 9 May 2022 15:18:42 +0300
From: Oz Shlomo <ozsh@...dia.com>
To: Sven Auhagen <sven.auhagen@...eatech.de>
Cc: Pablo Neira Ayuso <pablo@...filter.org>,
Felix Fietkau <nbd@....name>, netdev@...r.kernel.org,
netfilter-devel@...r.kernel.org, Florian Westphal <fw@...len.de>,
Paul Blakey <paulb@...dia.com>
Subject: Re: [PATCH net] netfilter: nf_flow_table: fix teardown flow timeout
Hi Sven,
On 5/9/2022 11:51 AM, Sven Auhagen wrote:
> Hi Oz,
>
> thank you, this patch fixes the race between ct gc and flowtable teardown.
> There is another big problem though in the code currently and I will send a patch
> in a minute.
>
> The flowtable teardown code always forces the ct state back to established
> and adds the established timeout to it even if it is in CLOSE or FIN WAIT
> which ultimately leads to a huge number of dead states in established state.
The system's design assumes that connections are added to nf flowtable
when they are in established state and are removed when they are about
to leave the established state.
It is the front-end's responsibility to enforce this behavior.
Currently nf flowtable is used by nft and tc act_ct.
act_ct removes the connection from nf flowtable when a fin/rst packet is
received. So the connection is still in established state when it is
removed from nf flow table (see tcf_ct_flow_table_lookup).
act_ct then calls nf_conntrack_in (for the same packet) which will
transition the connection to close/fin_wait state .
I am less familiar with nft internals.
>
> I will CC you on the patch, where I also stumbled upon your issue.
I reviewed the patch but I did not understand how it addresses the issue
that is fixed here.
The issue here is that IPS_OFFLOAD_BIT remains set when teardown is
called and the connection transitions to close/fin_wait state.
That can potentially race with the nf gc which assumes that the
connection is owned by nf flowtable and sets a one day timeout.
>
> Best
> Sven
>
> On Mon, May 09, 2022 at 10:29:16AM +0300, Oz Shlomo wrote:
>> Connections leaving the established state (due to RST / FIN TCP packets)
>> set the flow table teardown flag. The packet path continues to set lower
>> timeout value as per the new TCP state but the offload flag remains set.
>> Hence, the conntrack garbage collector may race to undo the timeout
>> adjustment of the packet path, leaving the conntrack entry in place with
>> the internal offload timeout (one day).
>>
>> Return the connection's ownership to conntrack upon teardown by clearing
>> the offload flag and fixing the established timeout value. The flow table
>> GC thread will asynchonrnously free the flow table and hardware offload
>> entries.
>>
>> Fixes: 1e5b2471bcc4 ("netfilter: nf_flow_table: teardown flow timeout race")
>> Signed-off-by: Oz Shlomo <ozsh@...dia.com>
>> Reviewed-by: Paul Blakey <paulb@...dia.com>
>> ---
>> net/netfilter/nf_flow_table_core.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
>> index 3db256da919b..ef080dbd4fd0 100644
>> --- a/net/netfilter/nf_flow_table_core.c
>> +++ b/net/netfilter/nf_flow_table_core.c
>> @@ -375,6 +375,9 @@ void flow_offload_teardown(struct flow_offload *flow)
>> set_bit(NF_FLOW_TEARDOWN, &flow->flags);
>>
>> flow_offload_fixup_ct_state(flow->ct);
>> + flow_offload_fixup_ct_timeout(flow->ct);
>> +
>> + clear_bit(IPS_OFFLOAD_BIT, &flow->ct->status);
>> }
>> EXPORT_SYMBOL_GPL(flow_offload_teardown);
>>
>> --
>> 1.8.3.1
>>
Powered by blists - more mailing lists