[PATCH 3.11 27/66] netem: free skbs in tree on reset

From: Greg Kroah-Hartman
Date: Fri Nov 01 2013 - 18:22:48 EST


3.11-stable review patch. If anyone has any objections, please let me know.

------------------

From: stephen hemminger <stephen@xxxxxxxxxxxxxxxxxx>

[ Upstream commit ff704050f2fc0f3382b5a70bba56a51a3feca79d ]

Netem can leak memory because packets get stored in red-black
tree and it is not cleared on reset.

Reported by: ÐÐÑÐÐÐÐ ÐÐÑÐÐÐ <adron@xxxxxxxxx>
Signed-off-by: Stephen Hemminger <stephen@xxxxxxxxxxxxxxxxxx>
Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
net/sched/sch_netem.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -358,6 +358,21 @@ static psched_time_t packet_len_2_sched_
return PSCHED_NS2TICKS(ticks);
}

+static void tfifo_reset(struct Qdisc *sch)
+{
+ struct netem_sched_data *q = qdisc_priv(sch);
+ struct rb_node *p;
+
+ while ((p = rb_first(&q->t_root))) {
+ struct sk_buff *skb = netem_rb_to_skb(p);
+
+ rb_erase(p, &q->t_root);
+ skb->next = NULL;
+ skb->prev = NULL;
+ kfree_skb(skb);
+ }
+}
+
static void tfifo_enqueue(struct sk_buff *nskb, struct Qdisc *sch)
{
struct netem_sched_data *q = qdisc_priv(sch);
@@ -613,6 +628,7 @@ static void netem_reset(struct Qdisc *sc
struct netem_sched_data *q = qdisc_priv(sch);

qdisc_reset_queue(sch);
+ tfifo_reset(sch);
if (q->qdisc)
qdisc_reset(q->qdisc);
qdisc_watchdog_cancel(&q->watchdog);


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/