Skip to content

netfilter: nf_conncount: fix gc and rbtree bugs

Florian Westphal netfilter-devel 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest5 patches 1 replyIn review
  2. v35 patches 0 repliesSuperseded
  3. v24 patches 0 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v13 patches0 repliesSuperseded

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5netfilter: nf_conncount: callers must hold rcu read locknet/netfilter/nf_conncount.c net/openvswitch/conntrack.c+4 -40 replies
2/5netfilter: nf_conncount: use per nf_conncount_data spinlocksnet/netfilter/nf_conncount.c+34 -291 reply
3/5netfilter: nf_conncount: split count_tree_node rbtree walk into helpernet/netfilter/nf_conncount.c+62 -400 replies
4/5netfilter: nf_conncount: add sequence counter to detect tree modificationsnet/netfilter/nf_conncount.c+19 -00 replies
5/5netfilter: nf_conncount: gc and rcu fixesnet/netfilter/nf_conncount.c+32 -220 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCH nf-next v4 0/5] netfilter: nf_conncount: fix gc and rbtree bugs

v4: address even more drive by findings:
- must switch to kzalloc, atm initial bitmap is random at start (which is harmless but wrong)
- PREEMPT_RT needs seqcnt <-> spinlock association so preemption is disabled

1) Extend RCU read lock scope in ovs, conncount API requires this. rcu_dereference_raw should not have been used here.
Note this adds new sparse warnings, but those are the lesser evil; lockdep support is more desirable wrt. rcu access correctness than sparse.

2) Replace rb_root with a new container structure in nf_conncount. Assign dedicated locks to each tree instead of a shared lock array. Use kvzalloc to ensure zero-initialized memory.

3) Split the count_tree_node rbtree walk into a helper. Add find_tree_node() to fetch matching rbtree nodes.

4) Add sequence counter to nf_conncount to detect tree modifications. Re-do lookups under lock if the counter changes. Prevent unsafe lockless iteration.

5) Fix tree_gc_worker wrap-around and protect rbtree iteration with a spinlock. Use disable_work_sync() and add rcu_barrier() to module exit.

Florian Westphal (5):
netfilter: nf_conncount: callers must hold rcu read lock
netfilter: nf_conncount: use per nf_conncount_data spinlocks
netfilter: nf_conncount: split count_tree_node rbtree walk into helper
netfilter: nf_conncount: add sequence counter to detect tree modifications
netfilter: nf_conncount: gc and rcu fixes

 net/netfilter/nf_conncount.c | 230 ++++++++++++++++++++++-------------
 net/openvswitch/conntrack.c  |   2 +-
 2 files changed, 144 insertions(+), 88 deletions(-)
Signature · 1 line
2.53.0