Skip to content

Commit

Permalink
net_sched: properly check for empty skb array on error path
Browse files Browse the repository at this point in the history
First, the check of &q->ring.queue against NULL is wrong, it
is always false. We should check the value rather than the address.

Secondly, we need the same check in pfifo_fast_reset() too,
as both ->reset() and ->destroy() are called in qdisc_destroy().

Fixes: c5ad119 ("net: sched: pfifo_fast use skb_array")
Reported-by: syzbot <[email protected]>
Cc: John Fastabend <[email protected]>
Signed-off-by: Cong Wang <[email protected]>
Acked-by: John Fastabend <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
congwang authored and davem330 committed Dec 19, 2017
1 parent 4eb50ce commit 1df94c3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion net/sched/sch_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,12 @@ static void pfifo_fast_reset(struct Qdisc *qdisc)
struct skb_array *q = band2list(priv, band);
struct sk_buff *skb;

/* NULL ring is possible if destroy path is due to a failed
* skb_array_init() in pfifo_fast_init() case.
*/
if (!q->ring.queue)
continue;

while ((skb = skb_array_consume_bh(q)) != NULL)
kfree_skb(skb);
}
Expand Down Expand Up @@ -719,7 +725,7 @@ static void pfifo_fast_destroy(struct Qdisc *sch)
/* NULL ring is possible if destroy path is due to a failed
* skb_array_init() in pfifo_fast_init() case.
*/
if (!&q->ring.queue)
if (!q->ring.queue)
continue;
/* Destroy ring but no need to kfree_skb because a call to
* pfifo_fast_reset() has already done that work.
Expand Down

0 comments on commit 1df94c3

Please sign in to comment.