Skip to content

Commit 22f7cec

Browse files
congwangdavem330
authored andcommitted
cls_flow: 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 ed14816 commit 22f7cec

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

net/sched/cls_flow.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,15 +372,21 @@ static const struct nla_policy flow_policy[TCA_FLOW_MAX + 1] = {
372372
[TCA_FLOW_PERTURB] = { .type = NLA_U32 },
373373
};
374374

375-
static void flow_destroy_filter_work(struct work_struct *work)
375+
static void __flow_destroy_filter(struct flow_filter *f)
376376
{
377-
struct flow_filter *f = container_of(work, struct flow_filter, work);
378-
379-
rtnl_lock();
380377
del_timer_sync(&f->perturb_timer);
381378
tcf_exts_destroy(&f->exts);
382379
tcf_em_tree_destroy(&f->ematches);
380+
tcf_exts_put_net(&f->exts);
383381
kfree(f);
382+
}
383+
384+
static void flow_destroy_filter_work(struct work_struct *work)
385+
{
386+
struct flow_filter *f = container_of(work, struct flow_filter, work);
387+
388+
rtnl_lock();
389+
__flow_destroy_filter(f);
384390
rtnl_unlock();
385391
}
386392

@@ -552,8 +558,10 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
552558

553559
*arg = fnew;
554560

555-
if (fold)
561+
if (fold) {
562+
tcf_exts_get_net(&fold->exts);
556563
call_rcu(&fold->rcu, flow_destroy_filter);
564+
}
557565
return 0;
558566

559567
err2:
@@ -570,6 +578,7 @@ static int flow_delete(struct tcf_proto *tp, void *arg, bool *last)
570578
struct flow_filter *f = arg;
571579

572580
list_del_rcu(&f->list);
581+
tcf_exts_get_net(&f->exts);
573582
call_rcu(&f->rcu, flow_destroy_filter);
574583
*last = list_empty(&head->filters);
575584
return 0;
@@ -594,7 +603,10 @@ static void flow_destroy(struct tcf_proto *tp)
594603

595604
list_for_each_entry_safe(f, next, &head->filters, list) {
596605
list_del_rcu(&f->list);
597-
call_rcu(&f->rcu, flow_destroy_filter);
606+
if (tcf_exts_get_net(&f->exts))
607+
call_rcu(&f->rcu, flow_destroy_filter);
608+
else
609+
__flow_destroy_filter(f);
598610
}
599611
kfree_rcu(head, rcu);
600612
}

0 commit comments

Comments
 (0)