net: sched: prevent a use after free
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 5 Feb 2020 11:53:30 +0000 (14:53 +0300)
committerDavid S. Miller <davem@davemloft.net>
Thu, 6 Feb 2020 13:00:12 +0000 (14:00 +0100)
The bug is that we call kfree_skb(skb) and then pass "skb" to
qdisc_pkt_len(skb) on the next line, which is a use after free.
Also Cong Wang points out that it's better to delay the actual
frees until we drop the rtnl lock so we should use rtnl_kfree_skbs()
instead of kfree_skb().

Cc: Cong Wang <xiyou.wangcong@gmail.com>
Fixes: ec97ecf1ebe4 ("net: sched: add Flow Queue PIE packet scheduler")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/sched/sch_fq_pie.c

index bbd0dea6b6b98e4136b75e33e21885a6d1b2e09a..214657eb3dfdf249267cdd888afef3af74987745 100644 (file)
@@ -349,9 +349,9 @@ static int fq_pie_change(struct Qdisc *sch, struct nlattr *opt,
        while (sch->q.qlen > sch->limit) {
                struct sk_buff *skb = fq_pie_qdisc_dequeue(sch);
 
-               kfree_skb(skb);
                len_dropped += qdisc_pkt_len(skb);
                num_dropped += 1;
+               rtnl_kfree_skbs(skb, skb);
        }
        qdisc_tree_reduce_backlog(sch, num_dropped, len_dropped);