Skip to content

Commit d2d31ea

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: conntrack: fix erronous removal of offload bit
The blamed commit exposes a possible issue with flow_offload_teardown(): We might remove the offload bit of a conntrack entry that has been offloaded again. 1. conntrack entry c1 is offloaded via flow f1 (f1->ct == c1). 2. f1 times out and is pushed back to slowpath, c1 offload bit is removed. Due to bug, f1 is not unlinked from rhashtable right away. 3. a new packet arrives for the flow and re-offload is triggered, i.e. f2->ct == c1. This is because lookup in flowtable skip entries with teardown bit set. 4. Next flowtable gc cycle finds f1 again 5. flow_offload_teardown() is called again for f1 and c1 offload bit is removed again, even though we have f2 referencing the same entry. This is harmless, but clearly not correct. Fix the bug that exposes this: set 'teardown = true' to have the gc callback unlink the flowtable entry from the table right away instead of the unintentional defer to the next round. Also prevent flow_offload_teardown() from fixing up the ct state more than once: We could also be called from the data path or a notifier, not only from the flowtable gc callback. NF_FLOW_TEARDOWN can never be unset, so we can use it as synchronization point: if we observe did not see a 0 -> 1 transition, then another CPU is already doing the ct state fixups for us. Fixes: 03428ca ("netfilter: conntrack: rework offload nf_conn timeout extension logic") Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 747fb84 commit d2d31ea

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

net/netfilter/nf_flow_table_core.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@ static void flow_offload_del(struct nf_flowtable *flow_table,
383383
void flow_offload_teardown(struct flow_offload *flow)
384384
{
385385
clear_bit(IPS_OFFLOAD_BIT, &flow->ct->status);
386-
set_bit(NF_FLOW_TEARDOWN, &flow->flags);
387-
flow_offload_fixup_ct(flow);
386+
if (!test_and_set_bit(NF_FLOW_TEARDOWN, &flow->flags))
387+
flow_offload_fixup_ct(flow);
388388
}
389389
EXPORT_SYMBOL_GPL(flow_offload_teardown);
390390

@@ -558,10 +558,12 @@ static void nf_flow_offload_gc_step(struct nf_flowtable *flow_table,
558558

559559
if (nf_flow_has_expired(flow) ||
560560
nf_ct_is_dying(flow->ct) ||
561-
nf_flow_custom_gc(flow_table, flow))
561+
nf_flow_custom_gc(flow_table, flow)) {
562562
flow_offload_teardown(flow);
563-
else if (!teardown)
563+
teardown = true;
564+
} else if (!teardown) {
564565
nf_flow_table_extend_ct_timeout(flow->ct);
566+
}
565567

566568
if (teardown) {
567569
if (test_bit(NF_FLOW_HW, &flow->flags)) {

0 commit comments

Comments
 (0)