Skip to content

Commit 0b2a598

Browse files
congwangdavem330
authored andcommitted
cls_basic: use tcf_exts_get_net() before call_rcu()
Hold netns refcnt before call_rcu() and release it after the tcf_exts_destroy() is done. Note, on ->destroy() path we have to respect the return value of tcf_exts_get_net(), on other paths it should always return true, so we don't need to care. Cc: Lucas Bates <lucasb@mojatatu.com> Cc: Jamal Hadi Salim <jhs@mojatatu.com> Cc: Jiri Pirko <jiri@resnulli.us> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e4b95c4 commit 0b2a598

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

net/sched/cls_basic.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,21 @@ static int basic_init(struct tcf_proto *tp)
8585
return 0;
8686
}
8787

88+
static void __basic_delete_filter(struct basic_filter *f)
89+
{
90+
tcf_exts_destroy(&f->exts);
91+
tcf_em_tree_destroy(&f->ematches);
92+
tcf_exts_put_net(&f->exts);
93+
kfree(f);
94+
}
95+
8896
static void basic_delete_filter_work(struct work_struct *work)
8997
{
9098
struct basic_filter *f = container_of(work, struct basic_filter, work);
9199

92100
rtnl_lock();
93-
tcf_exts_destroy(&f->exts);
94-
tcf_em_tree_destroy(&f->ematches);
101+
__basic_delete_filter(f);
95102
rtnl_unlock();
96-
97-
kfree(f);
98103
}
99104

100105
static void basic_delete_filter(struct rcu_head *head)
@@ -113,7 +118,10 @@ static void basic_destroy(struct tcf_proto *tp)
113118
list_for_each_entry_safe(f, n, &head->flist, link) {
114119
list_del_rcu(&f->link);
115120
tcf_unbind_filter(tp, &f->res);
116-
call_rcu(&f->rcu, basic_delete_filter);
121+
if (tcf_exts_get_net(&f->exts))
122+
call_rcu(&f->rcu, basic_delete_filter);
123+
else
124+
__basic_delete_filter(f);
117125
}
118126
kfree_rcu(head, rcu);
119127
}
@@ -125,6 +133,7 @@ static int basic_delete(struct tcf_proto *tp, void *arg, bool *last)
125133

126134
list_del_rcu(&f->link);
127135
tcf_unbind_filter(tp, &f->res);
136+
tcf_exts_get_net(&f->exts);
128137
call_rcu(&f->rcu, basic_delete_filter);
129138
*last = list_empty(&head->flist);
130139
return 0;
@@ -219,6 +228,7 @@ static int basic_change(struct net *net, struct sk_buff *in_skb,
219228
if (fold) {
220229
list_replace_rcu(&fold->link, &fnew->link);
221230
tcf_unbind_filter(tp, &fold->res);
231+
tcf_exts_get_net(&fold->exts);
222232
call_rcu(&fold->rcu, basic_delete_filter);
223233
} else {
224234
list_add_rcu(&fnew->link, &head->flist);

0 commit comments

Comments
 (0)