Skip to content

Commit 7cddd96

Browse files
Liping Zhangummakynes
authored andcommitted
netfilter: nf_ct_expect: use proper RCU list traversal/update APIs
We should use proper RCU list APIs to manipulate help->expectations, as we can dump the conntrack's expectations via nfnetlink, i.e. in ctnetlink_exp_ct_dump_table(), where only rcu_read_lock is acquired. So for list traversal, use hlist_for_each_entry_rcu; for list add/del, use hlist_add_head_rcu and hlist_del_rcu. Signed-off-by: Liping Zhang <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 207df81 commit 7cddd96

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

net/netfilter/nf_conntrack_expect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void nf_ct_unlink_expect_report(struct nf_conntrack_expect *exp,
5757
hlist_del_rcu(&exp->hnode);
5858
net->ct.expect_count--;
5959

60-
hlist_del(&exp->lnode);
60+
hlist_del_rcu(&exp->lnode);
6161
master_help->expecting[exp->class]--;
6262

6363
nf_ct_expect_event_report(IPEXP_DESTROY, exp, portid, report);
@@ -363,7 +363,7 @@ static void nf_ct_expect_insert(struct nf_conntrack_expect *exp)
363363
/* two references : one for hash insert, one for the timer */
364364
atomic_add(2, &exp->use);
365365

366-
hlist_add_head(&exp->lnode, &master_help->expectations);
366+
hlist_add_head_rcu(&exp->lnode, &master_help->expectations);
367367
master_help->expecting[exp->class]++;
368368

369369
hlist_add_head_rcu(&exp->hnode, &nf_ct_expect_hash[h]);

net/netfilter/nf_conntrack_netlink.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2680,8 +2680,8 @@ ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
26802680
last = (struct nf_conntrack_expect *)cb->args[1];
26812681
for (; cb->args[0] < nf_ct_expect_hsize; cb->args[0]++) {
26822682
restart:
2683-
hlist_for_each_entry(exp, &nf_ct_expect_hash[cb->args[0]],
2684-
hnode) {
2683+
hlist_for_each_entry_rcu(exp, &nf_ct_expect_hash[cb->args[0]],
2684+
hnode) {
26852685
if (l3proto && exp->tuple.src.l3num != l3proto)
26862686
continue;
26872687

@@ -2732,7 +2732,7 @@ ctnetlink_exp_ct_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
27322732
rcu_read_lock();
27332733
last = (struct nf_conntrack_expect *)cb->args[1];
27342734
restart:
2735-
hlist_for_each_entry(exp, &help->expectations, lnode) {
2735+
hlist_for_each_entry_rcu(exp, &help->expectations, lnode) {
27362736
if (l3proto && exp->tuple.src.l3num != l3proto)
27372737
continue;
27382738
if (cb->args[1]) {

0 commit comments

Comments
 (0)