Skip to contentSkip to conversation

qfq: don't leak skb if kzalloc fails

PATCH Superseded Florian Westphal 2 participants 3 messages Jun 8, 2016

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qfq: don't leak skb if kzalloc fails

When we need to create a new aggregate to enqueue the skb we need to kzalloc the new struct.

If that fails we returned ENOBUFS without freeing the skb.

Spotted during code review.

---
 net/sched/sch_qfq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_qfq.c +1 -1
index 8d2d8d9..435b970 100644
@@ -1236,7 +1236,7 @@ static int qfq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
 		err = qfq_change_agg(sch, cl, cl->agg->class_weight,
 				     qdisc_pkt_len(skb));
 		if (err)
-			return err;
+			return qdisc_drop(skb, sch);
 	}
 
 	err = qdisc_enqueue(skb, cl->qdisc);
Signature · 1 line
2.7.3
#1 lore raw
Quoted 17 lines · Florian Westphal

When we need to create a new aggregate to enqueue the skb we need to kzalloc the new struct.

If that fails we returned ENOBUFS without freeing the skb.

Spotted during code review.

---
 net/sched/sch_qfq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_qfq.c +0 -0
index 8d2d8d9..435b970 100644

net/sched/sch_qfq.c static int qfq_enqueue(struct sk_buff *skb, struct Qdisc *sch) · line 1242

Quoted 8 lines
net/sched/sch_qfq.c +1 -1
@@ -1236,7 +1236,7 @@ static int qfq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
 		err = qfq_change_agg(sch, cl, cl->agg->class_weight,
 				     qdisc_pkt_len(skb));
 		if (err)
-			return err;
+			return qdisc_drop(skb, sch);
 	}
 
 	err = qdisc_enqueue(skb, cl->qdisc);

Good catch, but it looks like you forgot :

	cl->qstats.drops++;
#2 lore raw
Quoted 25 lines · Eric Dumazet
Quoted 24 lines · Florian Westphal

When we need to create a new aggregate to enqueue the skb we need to kzalloc the new struct.

If that fails we returned ENOBUFS without freeing the skb.

Spotted during code review.

---
 net/sched/sch_qfq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_qfq.c +1 -1
index 8d2d8d9..435b970 100644
@@ -1236,7 +1236,7 @@ static int qfq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
 		err = qfq_change_agg(sch, cl, cl->agg->class_weight,
 				     qdisc_pkt_len(skb));
 		if (err)
-			return err;
+			return qdisc_drop(skb, sch);
 	}
 
Quoted 5 lines

net/sched/sch_qfq.c static int qfq_enqueue(struct sk_buff *skb, struct Qdisc *sch) · line 1242

Quoted 1 line
net/sched/sch_qfq.c +0 -0
 	err = qdisc_enqueue(skb, cl->qdisc);

Good catch, but it looks like you forgot :

	cl->qstats.drops++;

Thanks, we have too many stats :-/

I'll send a v2, thanks!