net_sched: move the empty tp check from ->destroy() to ->delete()
We could have a race condition where in ->classify() path we dereference tp->root and meanwhile a parallel ->destroy() makes it a NULL. Daniel cured this bug in commitd936377414
("net, sched: respect rcu grace period on cls destruction"). This happens when ->destroy() is called for deleting a filter to check if we are the last one in tp, this tp is still linked and visible at that time. The root cause of this problem is the semantic of ->destroy(), it does two things (for non-force case): 1) check if tp is empty 2) if tp is empty we could really destroy it and its caller, if cares, needs to check its return value to see if it is really destroyed. Therefore we can't unlink tp unless we know it is empty. As suggested by Daniel, we could actually move the test logic to ->delete() so that we can safely unlink tp after ->delete() tells us the last one is just deleted and before ->destroy(). Fixes:1e052be69d
("net_sched: destroy proto tp when all filters are gone") Cc: Roi Dayan <roid@mellanox.com> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: John Fastabend <john.fastabend@gmail.com> Cc: Jamal Hadi Salim <jhs@mojatatu.com> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
b1d9fc41aa
commit
763dbf6328
@@ -178,14 +178,11 @@ errout:
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
|
||||
static bool tcf_proto_destroy(struct tcf_proto *tp, bool force)
|
||||
static void tcf_proto_destroy(struct tcf_proto *tp)
|
||||
{
|
||||
if (tp->ops->destroy(tp, force)) {
|
||||
module_put(tp->ops->owner);
|
||||
kfree_rcu(tp, rcu);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
tp->ops->destroy(tp);
|
||||
module_put(tp->ops->owner);
|
||||
kfree_rcu(tp, rcu);
|
||||
}
|
||||
|
||||
void tcf_destroy_chain(struct tcf_proto __rcu **fl)
|
||||
@@ -194,7 +191,7 @@ void tcf_destroy_chain(struct tcf_proto __rcu **fl)
|
||||
|
||||
while ((tp = rtnl_dereference(*fl)) != NULL) {
|
||||
RCU_INIT_POINTER(*fl, tp->next);
|
||||
tcf_proto_destroy(tp, true);
|
||||
tcf_proto_destroy(tp);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL(tcf_destroy_chain);
|
||||
@@ -361,7 +358,7 @@ replay:
|
||||
RCU_INIT_POINTER(*back, next);
|
||||
tfilter_notify(net, skb, n, tp, fh,
|
||||
RTM_DELTFILTER, false);
|
||||
tcf_proto_destroy(tp, true);
|
||||
tcf_proto_destroy(tp);
|
||||
err = 0;
|
||||
goto errout;
|
||||
}
|
||||
@@ -372,24 +369,28 @@ replay:
|
||||
goto errout;
|
||||
}
|
||||
} else {
|
||||
bool last;
|
||||
|
||||
switch (n->nlmsg_type) {
|
||||
case RTM_NEWTFILTER:
|
||||
if (n->nlmsg_flags & NLM_F_EXCL) {
|
||||
if (tp_created)
|
||||
tcf_proto_destroy(tp, true);
|
||||
tcf_proto_destroy(tp);
|
||||
err = -EEXIST;
|
||||
goto errout;
|
||||
}
|
||||
break;
|
||||
case RTM_DELTFILTER:
|
||||
err = tp->ops->delete(tp, fh);
|
||||
err = tp->ops->delete(tp, fh, &last);
|
||||
if (err)
|
||||
goto errout;
|
||||
next = rtnl_dereference(tp->next);
|
||||
tfilter_notify(net, skb, n, tp, t->tcm_handle,
|
||||
RTM_DELTFILTER, false);
|
||||
if (tcf_proto_destroy(tp, false))
|
||||
if (last) {
|
||||
RCU_INIT_POINTER(*back, next);
|
||||
tcf_proto_destroy(tp);
|
||||
}
|
||||
goto errout;
|
||||
case RTM_GETTFILTER:
|
||||
err = tfilter_notify(net, skb, n, tp, fh,
|
||||
@@ -411,7 +412,7 @@ replay:
|
||||
tfilter_notify(net, skb, n, tp, fh, RTM_NEWTFILTER, false);
|
||||
} else {
|
||||
if (tp_created)
|
||||
tcf_proto_destroy(tp, true);
|
||||
tcf_proto_destroy(tp);
|
||||
}
|
||||
|
||||
errout:
|
||||
|
Reference in New Issue
Block a user