diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2010-12-22 14:39:59 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-12-22 14:39:59 -0500 |
commit | ee09b3c1cff0335137dc1b146488e4352f640f13 (patch) | |
tree | 4f21be5938205963ab73f8ca2ebdd0f4a65f8b17 /net | |
parent | 503b1a529a6b62b31904bab4699752c523cf76b2 (diff) |
sfq: fix sfq class stats handling
sfq_walk() runs without qdisc lock. By the time it selects a non empty
hash slot and sfq_dump_class_stats() is run (with lock held), slot might
have been freed : We then access q->slots[SFQ_EMPTY_SLOT], out of
bounds, and crash in slot_queue_walk()
On previous kernels, bug is here but out of bounds qs[SFQ_DEPTH] and
allot[SFQ_DEPTH] are located in struct sfq_sched_data, so no illegal
memory access happens, only possibly wrong data reported to user.
Also, slot_dequeue_tail() should make sure slot skb chain is correctly
terminated, or sfq_dump_class_stats() can access freed skbs.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/sched/sch_sfq.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/net/sched/sch_sfq.c b/net/sched/sch_sfq.c index 13322e8a0456..6a2f88fea6d8 100644 --- a/net/sched/sch_sfq.c +++ b/net/sched/sch_sfq.c | |||
@@ -281,6 +281,7 @@ static inline struct sk_buff *slot_dequeue_tail(struct sfq_slot *slot) | |||
281 | struct sk_buff *skb = slot->skblist_prev; | 281 | struct sk_buff *skb = slot->skblist_prev; |
282 | 282 | ||
283 | slot->skblist_prev = skb->prev; | 283 | slot->skblist_prev = skb->prev; |
284 | skb->prev->next = (struct sk_buff *)slot; | ||
284 | skb->next = skb->prev = NULL; | 285 | skb->next = skb->prev = NULL; |
285 | return skb; | 286 | return skb; |
286 | } | 287 | } |
@@ -608,14 +609,19 @@ static int sfq_dump_class_stats(struct Qdisc *sch, unsigned long cl, | |||
608 | struct gnet_dump *d) | 609 | struct gnet_dump *d) |
609 | { | 610 | { |
610 | struct sfq_sched_data *q = qdisc_priv(sch); | 611 | struct sfq_sched_data *q = qdisc_priv(sch); |
611 | const struct sfq_slot *slot = &q->slots[q->ht[cl - 1]]; | 612 | sfq_index idx = q->ht[cl - 1]; |
612 | struct gnet_stats_queue qs = { .qlen = slot->qlen }; | 613 | struct gnet_stats_queue qs = { 0 }; |
613 | struct tc_sfq_xstats xstats = { .allot = slot->allot }; | 614 | struct tc_sfq_xstats xstats = { 0 }; |
614 | struct sk_buff *skb; | 615 | struct sk_buff *skb; |
615 | 616 | ||
616 | slot_queue_walk(slot, skb) | 617 | if (idx != SFQ_EMPTY_SLOT) { |
617 | qs.backlog += qdisc_pkt_len(skb); | 618 | const struct sfq_slot *slot = &q->slots[idx]; |
618 | 619 | ||
620 | xstats.allot = slot->allot; | ||
621 | qs.qlen = slot->qlen; | ||
622 | slot_queue_walk(slot, skb) | ||
623 | qs.backlog += qdisc_pkt_len(skb); | ||
624 | } | ||
619 | if (gnet_stats_copy_queue(d, &qs) < 0) | 625 | if (gnet_stats_copy_queue(d, &qs) < 0) |
620 | return -1; | 626 | return -1; |
621 | return gnet_stats_copy_app(d, &xstats, sizeof(xstats)); | 627 | return gnet_stats_copy_app(d, &xstats, sizeof(xstats)); |