Skip to content

Commit ed14816

Browse files
congwangdavem330
authored andcommitted
cls_cgroup: 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 aae2c35 commit ed14816

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

net/sched/cls_cgroup.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,21 @@ static const struct nla_policy cgroup_policy[TCA_CGROUP_MAX + 1] = {
6060
[TCA_CGROUP_EMATCHES] = { .type = NLA_NESTED },
6161
};
6262

63+
static void __cls_cgroup_destroy(struct cls_cgroup_head *head)
64+
{
65+
tcf_exts_destroy(&head->exts);
66+
tcf_em_tree_destroy(&head->ematches);
67+
tcf_exts_put_net(&head->exts);
68+
kfree(head);
69+
}
70+
6371
static void cls_cgroup_destroy_work(struct work_struct *work)
6472
{
6573
struct cls_cgroup_head *head = container_of(work,
6674
struct cls_cgroup_head,
6775
work);
6876
rtnl_lock();
69-
tcf_exts_destroy(&head->exts);
70-
tcf_em_tree_destroy(&head->ematches);
71-
kfree(head);
77+
__cls_cgroup_destroy(head);
7278
rtnl_unlock();
7379
}
7480

@@ -124,8 +130,10 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,
124130
goto errout;
125131

126132
rcu_assign_pointer(tp->root, new);
127-
if (head)
133+
if (head) {
134+
tcf_exts_get_net(&head->exts);
128135
call_rcu(&head->rcu, cls_cgroup_destroy_rcu);
136+
}
129137
return 0;
130138
errout:
131139
tcf_exts_destroy(&new->exts);
@@ -138,8 +146,12 @@ static void cls_cgroup_destroy(struct tcf_proto *tp)
138146
struct cls_cgroup_head *head = rtnl_dereference(tp->root);
139147

140148
/* Head can still be NULL due to cls_cgroup_init(). */
141-
if (head)
142-
call_rcu(&head->rcu, cls_cgroup_destroy_rcu);
149+
if (head) {
150+
if (tcf_exts_get_net(&head->exts))
151+
call_rcu(&head->rcu, cls_cgroup_destroy_rcu);
152+
else
153+
__cls_cgroup_destroy(head);
154+
}
143155
}
144156

145157
static int cls_cgroup_delete(struct tcf_proto *tp, void *arg, bool *last)

0 commit comments

Comments
 (0)