]> git.baikalelectronics.ru Git - kernel.git/commit
netfilter: nf_conncount: split gc in two phases
authorFlorian Westphal <fw@strlen.de>
Fri, 28 Dec 2018 00:24:44 +0000 (01:24 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Sat, 29 Dec 2018 01:45:19 +0000 (02:45 +0100)
commit6485c8ece2c36874b796bfdbded13775b82b13a4
treeabac7ea27b0b8414e427da2ed4995d1c14a85b80
parentf29ed9376e917fac567aa3b0ae76b410470e460a
netfilter: nf_conncount: split gc in two phases

The lockless workqueue garbage collector can race with packet path
garbage collector to delete list nodes, as it calls tree_nodes_free()
with the addresses of nodes that might have been free'd already from
another cpu.

To fix this, split gc into two phases.

One phase to perform gc on the connections: From a locking perspective,
this is the same as count_tree(): we hold rcu lock, but we do not
change the tree, we only change the nodes' contents.

The second phase acquires the tree lock and reaps empty nodes.
This avoids a race condition of the garbage collection vs.  packet path:
If a node has been free'd already, the second phase won't find it anymore.

This second phase is, from locking perspective, same as insert_tree().

The former only modifies nodes (list content, count), latter modifies
the tree itself (rb_erase or rb_insert).

Fixes: 638ffa8ee8a04 ("netfilter: nf_conncount: Add list lock and gc worker, and RCU for init tree search")
Reviewed-by: Shawn Bohrer <sbohrer@cloudflare.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nf_conncount.c