Skip to content

Commit

Permalink
net: sched: fix clsact init error path
Browse files Browse the repository at this point in the history
Since in qdisc_create, the destroy op is called when init fails, we
don't do cleanup in init and leave it up to destroy.
This fixes use-after-free when trying to put already freed block.

Fixes: 6e40cf2 ("net: sched: use extended variants of block_get/put in ingress and clsact qdiscs")
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Acked-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jiri Pirko authored and David S. Miller committed Dec 15, 2017
1 parent c05fad5 commit 343723d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 2 additions & 2 deletions net/sched/cls_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q,
{
struct tcf_chain *chain;

if (!block)
return;
/* Hold a refcnt for all chains, except 0, so that they don't disappear
* while we are iterating.
*/
Expand All @@ -377,8 +379,6 @@ void tcf_block_put(struct tcf_block *block)
{
struct tcf_block_ext_info ei = {0, };

if (!block)
return;
tcf_block_put_ext(block, block->q, &ei);
}

Expand Down
6 changes: 1 addition & 5 deletions net/sched/sch_ingress.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,14 @@ static int clsact_init(struct Qdisc *sch, struct nlattr *opt)

err = tcf_block_get_ext(&q->egress_block, sch, &q->egress_block_info);
if (err)
goto err_egress_block_get;
return err;

net_inc_ingress_queue();
net_inc_egress_queue();

sch->flags |= TCQ_F_CPUSTATS;

return 0;

err_egress_block_get:
tcf_block_put_ext(q->ingress_block, sch, &q->ingress_block_info);
return err;
}

static void clsact_destroy(struct Qdisc *sch)
Expand Down

0 comments on commit 343723d

Please sign in to comment.