Skip to content

Commit aae2c35

Browse files
congwangdavem330
authored andcommitted
cls_bpf: 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 0b2a598 commit aae2c35

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

net/sched/cls_bpf.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ static int cls_bpf_init(struct tcf_proto *tp)
249249
static void __cls_bpf_delete_prog(struct cls_bpf_prog *prog)
250250
{
251251
tcf_exts_destroy(&prog->exts);
252+
tcf_exts_put_net(&prog->exts);
252253

253254
if (cls_bpf_is_ebpf(prog))
254255
bpf_prog_put(prog->filter);
@@ -282,7 +283,10 @@ static void __cls_bpf_delete(struct tcf_proto *tp, struct cls_bpf_prog *prog)
282283
cls_bpf_stop_offload(tp, prog);
283284
list_del_rcu(&prog->link);
284285
tcf_unbind_filter(tp, &prog->res);
285-
call_rcu(&prog->rcu, cls_bpf_delete_prog_rcu);
286+
if (tcf_exts_get_net(&prog->exts))
287+
call_rcu(&prog->rcu, cls_bpf_delete_prog_rcu);
288+
else
289+
__cls_bpf_delete_prog(prog);
286290
}
287291

288292
static int cls_bpf_delete(struct tcf_proto *tp, void *arg, bool *last)
@@ -516,6 +520,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
516520
if (oldprog) {
517521
list_replace_rcu(&oldprog->link, &prog->link);
518522
tcf_unbind_filter(tp, &oldprog->res);
523+
tcf_exts_get_net(&oldprog->exts);
519524
call_rcu(&oldprog->rcu, cls_bpf_delete_prog_rcu);
520525
} else {
521526
list_add_rcu(&prog->link, &head->plist);

0 commit comments

Comments
 (0)