Skip to content

Commit

Permalink
net: sched: fix crash when deleting secondary chains
Browse files Browse the repository at this point in the history
If you flush (delete) a filter chain other than chain 0 (such as when
deleting the device), the kernel may run into a use-after-free. The
chain refcount must not be decremented unless we are sure we are done
with the chain.

To reproduce the bug, run:
    ip link add dtest type dummy
    tc qdisc add dev dtest ingress
    tc filter add dev dtest chain 1  parent ffff: flower
    ip link del dtest

Introduced in: commit f93e1cd ("net/sched: fix filter flushing"),
but unless you have KAsan or luck, you won't notice it until
commit 0dadc11 ("cls_flower: use tcf_exts_get_net() before call_rcu()")

Fixes: f93e1cd ("net/sched: fix filter flushing")
Acked-by: Jiri Pirko <[email protected]>
Signed-off-by: Roman Kapl <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
rkapl authored and davem330 committed Nov 23, 2017
1 parent 0cc0350 commit d7aa04a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions net/sched/cls_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,14 @@ static void tcf_chain_head_change(struct tcf_chain *chain,

static void tcf_chain_flush(struct tcf_chain *chain)
{
struct tcf_proto *tp;
struct tcf_proto *tp = rtnl_dereference(chain->filter_chain);

tcf_chain_head_change(chain, NULL);
while ((tp = rtnl_dereference(chain->filter_chain)) != NULL) {
while (tp) {
RCU_INIT_POINTER(chain->filter_chain, tp->next);
tcf_chain_put(chain);
tcf_proto_destroy(tp);
tp = rtnl_dereference(chain->filter_chain);
tcf_chain_put(chain);
}
}

Expand Down

0 comments on commit d7aa04a

Please sign in to comment.