Skip to content

Commit 3fd51de

Browse files
congwangdavem330
authored andcommitted
cls_route: 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 57767e7 commit 3fd51de

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

net/sched/cls_route.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,19 @@ static int route4_init(struct tcf_proto *tp)
257257
return 0;
258258
}
259259

260+
static void __route4_delete_filter(struct route4_filter *f)
261+
{
262+
tcf_exts_destroy(&f->exts);
263+
tcf_exts_put_net(&f->exts);
264+
kfree(f);
265+
}
266+
260267
static void route4_delete_filter_work(struct work_struct *work)
261268
{
262269
struct route4_filter *f = container_of(work, struct route4_filter, work);
263270

264271
rtnl_lock();
265-
tcf_exts_destroy(&f->exts);
266-
kfree(f);
272+
__route4_delete_filter(f);
267273
rtnl_unlock();
268274
}
269275

@@ -297,7 +303,10 @@ static void route4_destroy(struct tcf_proto *tp)
297303
next = rtnl_dereference(f->next);
298304
RCU_INIT_POINTER(b->ht[h2], next);
299305
tcf_unbind_filter(tp, &f->res);
300-
call_rcu(&f->rcu, route4_delete_filter);
306+
if (tcf_exts_get_net(&f->exts))
307+
call_rcu(&f->rcu, route4_delete_filter);
308+
else
309+
__route4_delete_filter(f);
301310
}
302311
}
303312
RCU_INIT_POINTER(head->table[h1], NULL);
@@ -338,6 +347,7 @@ static int route4_delete(struct tcf_proto *tp, void *arg, bool *last)
338347

339348
/* Delete it */
340349
tcf_unbind_filter(tp, &f->res);
350+
tcf_exts_get_net(&f->exts);
341351
call_rcu(&f->rcu, route4_delete_filter);
342352

343353
/* Strip RTNL protected tree */
@@ -541,6 +551,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,
541551
*arg = f;
542552
if (fold) {
543553
tcf_unbind_filter(tp, &fold->res);
554+
tcf_exts_get_net(&fold->exts);
544555
call_rcu(&fold->rcu, route4_delete_filter);
545556
}
546557
return 0;

0 commit comments

Comments
 (0)