Skip to content

Commit 0dadc11

Browse files
congwangdavem330
authored andcommitted
cls_flower: 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 22f7cec commit 0dadc11

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

net/sched/cls_flower.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,19 @@ static int fl_init(struct tcf_proto *tp)
218218
return 0;
219219
}
220220

221+
static void __fl_destroy_filter(struct cls_fl_filter *f)
222+
{
223+
tcf_exts_destroy(&f->exts);
224+
tcf_exts_put_net(&f->exts);
225+
kfree(f);
226+
}
227+
221228
static void fl_destroy_filter_work(struct work_struct *work)
222229
{
223230
struct cls_fl_filter *f = container_of(work, struct cls_fl_filter, work);
224231

225232
rtnl_lock();
226-
tcf_exts_destroy(&f->exts);
227-
kfree(f);
233+
__fl_destroy_filter(f);
228234
rtnl_unlock();
229235
}
230236

@@ -318,7 +324,10 @@ static void __fl_delete(struct tcf_proto *tp, struct cls_fl_filter *f)
318324
if (!tc_skip_hw(f->flags))
319325
fl_hw_destroy_filter(tp, f);
320326
tcf_unbind_filter(tp, &f->res);
321-
call_rcu(&f->rcu, fl_destroy_filter);
327+
if (tcf_exts_get_net(&f->exts))
328+
call_rcu(&f->rcu, fl_destroy_filter);
329+
else
330+
__fl_destroy_filter(f);
322331
}
323332

324333
static void fl_destroy_sleepable(struct work_struct *work)
@@ -988,6 +997,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
988997
idr_replace_ext(&head->handle_idr, fnew, fnew->handle);
989998
list_replace_rcu(&fold->list, &fnew->list);
990999
tcf_unbind_filter(tp, &fold->res);
1000+
tcf_exts_get_net(&fold->exts);
9911001
call_rcu(&fold->rcu, fl_destroy_filter);
9921002
} else {
9931003
list_add_tail_rcu(&fnew->list, &head->filters);

0 commit comments

Comments
 (0)