Commit f2b75105 authored by Cong Wang's avatar Cong Wang Committed by David S. Miller

cls_tcindex: 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: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 96585063
...@@ -139,13 +139,19 @@ static int tcindex_init(struct tcf_proto *tp) ...@@ -139,13 +139,19 @@ static int tcindex_init(struct tcf_proto *tp)
return 0; return 0;
} }
static void __tcindex_destroy_rexts(struct tcindex_filter_result *r)
{
tcf_exts_destroy(&r->exts);
tcf_exts_put_net(&r->exts);
}
static void tcindex_destroy_rexts_work(struct work_struct *work) static void tcindex_destroy_rexts_work(struct work_struct *work)
{ {
struct tcindex_filter_result *r; struct tcindex_filter_result *r;
r = container_of(work, struct tcindex_filter_result, work); r = container_of(work, struct tcindex_filter_result, work);
rtnl_lock(); rtnl_lock();
tcf_exts_destroy(&r->exts); __tcindex_destroy_rexts(r);
rtnl_unlock(); rtnl_unlock();
} }
...@@ -158,14 +164,20 @@ static void tcindex_destroy_rexts(struct rcu_head *head) ...@@ -158,14 +164,20 @@ static void tcindex_destroy_rexts(struct rcu_head *head)
tcf_queue_work(&r->work); tcf_queue_work(&r->work);
} }
static void __tcindex_destroy_fexts(struct tcindex_filter *f)
{
tcf_exts_destroy(&f->result.exts);
tcf_exts_put_net(&f->result.exts);
kfree(f);
}
static void tcindex_destroy_fexts_work(struct work_struct *work) static void tcindex_destroy_fexts_work(struct work_struct *work)
{ {
struct tcindex_filter *f = container_of(work, struct tcindex_filter, struct tcindex_filter *f = container_of(work, struct tcindex_filter,
work); work);
rtnl_lock(); rtnl_lock();
tcf_exts_destroy(&f->result.exts); __tcindex_destroy_fexts(f);
kfree(f);
rtnl_unlock(); rtnl_unlock();
} }
...@@ -210,10 +222,17 @@ static int tcindex_delete(struct tcf_proto *tp, void *arg, bool *last) ...@@ -210,10 +222,17 @@ static int tcindex_delete(struct tcf_proto *tp, void *arg, bool *last)
* grace period, since converted-to-rcu actions are relying on that * grace period, since converted-to-rcu actions are relying on that
* in cleanup() callback * in cleanup() callback
*/ */
if (f) if (f) {
call_rcu(&f->rcu, tcindex_destroy_fexts); if (tcf_exts_get_net(&f->result.exts))
else call_rcu(&f->rcu, tcindex_destroy_fexts);
call_rcu(&r->rcu, tcindex_destroy_rexts); else
__tcindex_destroy_fexts(f);
} else {
if (tcf_exts_get_net(&r->exts))
call_rcu(&r->rcu, tcindex_destroy_rexts);
else
__tcindex_destroy_rexts(r);
}
*last = false; *last = false;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment