Skip to content

Commit ace53fd

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: conntrack: remove __nf_ct_unconfirmed_destroy
Its not needed anymore: A. If entry is totally new, then the rcu-protected resource must already have been removed from global visibility before call to nf_ct_iterate_destroy. B. If entry was allocated before, but is not yet in the hash table (uncofirmed case), genid gets incremented and synchronize_rcu() call makes sure access has completed. C. Next attempt to peek at extension area will fail for unconfirmed conntracks, because ext->genid != genid. D. Conntracks in the hash are iterated as before. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 42df4fb commit ace53fd

File tree

3 files changed

+13
-39
lines changed

3 files changed

+13
-39
lines changed

net/netfilter/nf_conntrack_core.c

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,34 +2457,6 @@ static int iter_net_only(struct nf_conn *i, void *data)
24572457
return d->iter(i, d->data);
24582458
}
24592459

2460-
static void
2461-
__nf_ct_unconfirmed_destroy(struct net *net)
2462-
{
2463-
int cpu;
2464-
2465-
for_each_possible_cpu(cpu) {
2466-
struct nf_conntrack_tuple_hash *h;
2467-
struct hlist_nulls_node *n;
2468-
struct ct_pcpu *pcpu;
2469-
2470-
pcpu = per_cpu_ptr(net->ct.pcpu_lists, cpu);
2471-
2472-
spin_lock_bh(&pcpu->lock);
2473-
hlist_nulls_for_each_entry(h, n, &pcpu->unconfirmed, hnnode) {
2474-
struct nf_conn *ct;
2475-
2476-
ct = nf_ct_tuplehash_to_ctrack(h);
2477-
2478-
/* we cannot call iter() on unconfirmed list, the
2479-
* owning cpu can reallocate ct->ext at any time.
2480-
*/
2481-
set_bit(IPS_DYING_BIT, &ct->status);
2482-
}
2483-
spin_unlock_bh(&pcpu->lock);
2484-
cond_resched();
2485-
}
2486-
}
2487-
24882460
void nf_ct_iterate_cleanup_net(struct net *net,
24892461
int (*iter)(struct nf_conn *i, void *data),
24902462
void *data, u32 portid, int report)
@@ -2527,26 +2499,34 @@ nf_ct_iterate_destroy(int (*iter)(struct nf_conn *i, void *data), void *data)
25272499

25282500
if (atomic_read(&cnet->count) == 0)
25292501
continue;
2530-
__nf_ct_unconfirmed_destroy(net);
25312502
nf_queue_nf_hook_drop(net);
25322503
}
25332504
up_read(&net_rwsem);
25342505

25352506
/* Need to wait for netns cleanup worker to finish, if its
25362507
* running -- it might have deleted a net namespace from
2537-
* the global list, so our __nf_ct_unconfirmed_destroy() might
2538-
* not have affected all namespaces.
2508+
* the global list, so hook drop above might not have
2509+
* affected all namespaces.
25392510
*/
25402511
net_ns_barrier();
25412512

2542-
/* a conntrack could have been unlinked from unconfirmed list
2543-
* before we grabbed pcpu lock in __nf_ct_unconfirmed_destroy().
2513+
/* a skb w. unconfirmed conntrack could have been reinjected just
2514+
* before we called nf_queue_nf_hook_drop().
2515+
*
25442516
* This makes sure its inserted into conntrack table.
25452517
*/
25462518
synchronize_net();
25472519

25482520
nf_ct_ext_bump_genid();
25492521
nf_ct_iterate_cleanup(iter, data, 0, 0);
2522+
2523+
/* Another cpu might be in a rcu read section with
2524+
* rcu protected pointer cleared in iter callback
2525+
* or hidden via nf_ct_ext_bump_genid() above.
2526+
*
2527+
* Wait until those are done.
2528+
*/
2529+
synchronize_rcu();
25502530
}
25512531
EXPORT_SYMBOL_GPL(nf_ct_iterate_destroy);
25522532

net/netfilter/nf_conntrack_helper.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,6 @@ void nf_conntrack_helper_unregister(struct nf_conntrack_helper *me)
468468

469469
nf_ct_expect_iterate_destroy(expect_iter_me, NULL);
470470
nf_ct_iterate_destroy(unhelp, me);
471-
472-
/* Maybe someone has gotten the helper already when unhelp above.
473-
* So need to wait it.
474-
*/
475-
synchronize_rcu();
476471
}
477472
EXPORT_SYMBOL_GPL(nf_conntrack_helper_unregister);
478473

net/netfilter/nfnetlink_cttimeout.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,6 @@ static void __exit cttimeout_exit(void)
674674
RCU_INIT_POINTER(nf_ct_timeout_hook, NULL);
675675

676676
nf_ct_iterate_destroy(untimeout, NULL);
677-
synchronize_rcu();
678677
}
679678

680679
module_init(cttimeout_init);

0 commit comments

Comments
 (0)