Skip to content

Commit f2b7510

Browse files
congwangdavem330
authored andcommitted
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 <[email protected]> Cc: Jamal Hadi Salim <[email protected]> Cc: Jiri Pirko <[email protected]> Signed-off-by: Cong Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9658506 commit f2b7510

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

net/sched/cls_tcindex.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,19 @@ static int tcindex_init(struct tcf_proto *tp)
139139
return 0;
140140
}
141141

142+
static void __tcindex_destroy_rexts(struct tcindex_filter_result *r)
143+
{
144+
tcf_exts_destroy(&r->exts);
145+
tcf_exts_put_net(&r->exts);
146+
}
147+
142148
static void tcindex_destroy_rexts_work(struct work_struct *work)
143149
{
144150
struct tcindex_filter_result *r;
145151

146152
r = container_of(work, struct tcindex_filter_result, work);
147153
rtnl_lock();
148-
tcf_exts_destroy(&r->exts);
154+
__tcindex_destroy_rexts(r);
149155
rtnl_unlock();
150156
}
151157

@@ -158,14 +164,20 @@ static void tcindex_destroy_rexts(struct rcu_head *head)
158164
tcf_queue_work(&r->work);
159165
}
160166

167+
static void __tcindex_destroy_fexts(struct tcindex_filter *f)
168+
{
169+
tcf_exts_destroy(&f->result.exts);
170+
tcf_exts_put_net(&f->result.exts);
171+
kfree(f);
172+
}
173+
161174
static void tcindex_destroy_fexts_work(struct work_struct *work)
162175
{
163176
struct tcindex_filter *f = container_of(work, struct tcindex_filter,
164177
work);
165178

166179
rtnl_lock();
167-
tcf_exts_destroy(&f->result.exts);
168-
kfree(f);
180+
__tcindex_destroy_fexts(f);
169181
rtnl_unlock();
170182
}
171183

@@ -210,10 +222,17 @@ static int tcindex_delete(struct tcf_proto *tp, void *arg, bool *last)
210222
* grace period, since converted-to-rcu actions are relying on that
211223
* in cleanup() callback
212224
*/
213-
if (f)
214-
call_rcu(&f->rcu, tcindex_destroy_fexts);
215-
else
216-
call_rcu(&r->rcu, tcindex_destroy_rexts);
225+
if (f) {
226+
if (tcf_exts_get_net(&f->result.exts))
227+
call_rcu(&f->rcu, tcindex_destroy_fexts);
228+
else
229+
__tcindex_destroy_fexts(f);
230+
} else {
231+
if (tcf_exts_get_net(&r->exts))
232+
call_rcu(&r->rcu, tcindex_destroy_rexts);
233+
else
234+
__tcindex_destroy_rexts(r);
235+
}
217236

218237
*last = false;
219238
return 0;

0 commit comments

Comments
 (0)