* [PATCH] pkt_sched: Change misleading code in class delete.
@ 2009-03-14 14:45 Jarek Poplawski
2009-03-15 12:35 ` [PATCH v2] " Jarek Poplawski
0 siblings, 1 reply; 3+ messages in thread
From: Jarek Poplawski @ 2009-03-14 14:45 UTC (permalink / raw)
To: David Miller; +Cc: m0sia, Patrick McHardy, netdev
While looking for a possible reason of bugzilla report on HTB oops:
http://bugzilla.kernel.org/show_bug.cgi?id=12858
I found the code in htb_delete calling htb_destroy_class on zero
refcount is very misleading: it can suggest this is a common path, and
destroy is called under sch_tree_lock. Actually, this can never happen
like this because before deletion cops->get() is done, and after
delete a class is still used by tclass_notify. The class destroy is
always called from cops->put(), so without sch_tree_lock.
This doesn't mean much now (since 2.6.27) because all vulnerable calls
were moved from htb_destroy_class to htb_delete, but there was a bug
in older kernels. The same change is done for other classful scheds,
which, it seems, didn't have similar locking problems here.
Reported-by: m0sia@m0sia.ru
Signed-off-by: Jarek Poplawski <jarkao2@gmail.com>
---
net/sched/sch_cbq.c | 7 +++++--
net/sched/sch_drr.c | 7 +++++--
net/sched/sch_hfsc.c | 7 +++++--
net/sched/sch_htb.c | 7 +++++--
4 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c
index 9e43ed9..002442a 100644
--- a/net/sched/sch_cbq.c
+++ b/net/sched/sch_cbq.c
@@ -1960,8 +1960,11 @@ static int cbq_delete(struct Qdisc *sch, unsigned long arg)
cbq_rmprio(q, cl);
sch_tree_unlock(sch);
- if (--cl->refcnt == 0)
- cbq_destroy_class(sch, cl);
+ BUG_ON(--cl->refcnt == 0);
+ /*
+ * This shouldn't happen: we hold one cops->get() when called
+ * from tc_ctl_tclass; the destroy is done from cops->put().
+ */
return 0;
}
diff --git a/net/sched/sch_drr.c b/net/sched/sch_drr.c
index e36e94a..00e20d5 100644
--- a/net/sched/sch_drr.c
+++ b/net/sched/sch_drr.c
@@ -155,8 +155,11 @@ static int drr_delete_class(struct Qdisc *sch, unsigned long arg)
drr_purge_queue(cl);
qdisc_class_hash_remove(&q->clhash, &cl->common);
- if (--cl->refcnt == 0)
- drr_destroy_class(sch, cl);
+ BUG_ON(--cl->refcnt == 0);
+ /*
+ * This shouldn't happen: we hold one cops->get() when called
+ * from tc_ctl_tclass; the destroy is done from cops->put().
+ */
sch_tree_unlock(sch);
return 0;
diff --git a/net/sched/sch_hfsc.c b/net/sched/sch_hfsc.c
index 74226b2..a516aa4 100644
--- a/net/sched/sch_hfsc.c
+++ b/net/sched/sch_hfsc.c
@@ -1139,8 +1139,11 @@ hfsc_delete_class(struct Qdisc *sch, unsigned long arg)
hfsc_purge_queue(sch, cl);
qdisc_class_hash_remove(&q->clhash, &cl->cl_common);
- if (--cl->refcnt == 0)
- hfsc_destroy_class(sch, cl);
+ BUG_ON(--cl->refcnt == 0);
+ /*
+ * This shouldn't happen: we hold one cops->get() when called
+ * from tc_ctl_tclass; the destroy is done from cops->put().
+ */
sch_tree_unlock(sch);
return 0;
diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c
index 355974f..a4b682b 100644
--- a/net/sched/sch_htb.c
+++ b/net/sched/sch_htb.c
@@ -1275,8 +1275,11 @@ static int htb_delete(struct Qdisc *sch, unsigned long arg)
if (last_child)
htb_parent_to_leaf(q, cl, new_q);
- if (--cl->refcnt == 0)
- htb_destroy_class(sch, cl);
+ BUG_ON(--cl->refcnt == 0);
+ /*
+ * This shouldn't happen: we hold one cops->get() when called
+ * from tc_ctl_tclass; the destroy is done from cops->put().
+ */
sch_tree_unlock(sch);
return 0;
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v2] pkt_sched: Change misleading code in class delete.
2009-03-14 14:45 [PATCH] pkt_sched: Change misleading code in class delete Jarek Poplawski
@ 2009-03-15 12:35 ` Jarek Poplawski
2009-03-16 3:00 ` David Miller
0 siblings, 1 reply; 3+ messages in thread
From: Jarek Poplawski @ 2009-03-15 12:35 UTC (permalink / raw)
To: David Miller; +Cc: m0sia, Patrick McHardy, netdev
A few words were missing...
----------------> take 2
While looking for a possible reason of bugzilla report on HTB oops:
http://bugzilla.kernel.org/show_bug.cgi?id=12858
I found the code in htb_delete calling htb_destroy_class on zero
refcount is very misleading: it can suggest this is a common path, and
destroy is called under sch_tree_lock. Actually, this can never happen
like this because before deletion cops->get() is done, and after
delete a class is still used by tclass_notify. The class destroy is
always called from cops->put(), so without sch_tree_lock.
This doesn't mean much now (since 2.6.27) because all vulnerable calls
were moved from htb_destroy_class to htb_delete, but there was a bug
in older kernels. The same change is done for other classful scheds,
which, it seems, didn't have similar locking problems here.
Reported-by: m0sia <m0sia@m0sia.ru>
Signed-off-by: Jarek Poplawski <jarkao2@gmail.com>
---
net/sched/sch_cbq.c | 7 +++++--
net/sched/sch_drr.c | 7 +++++--
net/sched/sch_hfsc.c | 7 +++++--
net/sched/sch_htb.c | 7 +++++--
4 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c
index 9e43ed9..002442a 100644
--- a/net/sched/sch_cbq.c
+++ b/net/sched/sch_cbq.c
@@ -1960,8 +1960,11 @@ static int cbq_delete(struct Qdisc *sch, unsigned long arg)
cbq_rmprio(q, cl);
sch_tree_unlock(sch);
- if (--cl->refcnt == 0)
- cbq_destroy_class(sch, cl);
+ BUG_ON(--cl->refcnt == 0);
+ /*
+ * This shouldn't happen: we "hold" one cops->get() when called
+ * from tc_ctl_tclass; the destroy method is done from cops->put().
+ */
return 0;
}
diff --git a/net/sched/sch_drr.c b/net/sched/sch_drr.c
index e36e94a..00e20d5 100644
--- a/net/sched/sch_drr.c
+++ b/net/sched/sch_drr.c
@@ -155,8 +155,11 @@ static int drr_delete_class(struct Qdisc *sch, unsigned long arg)
drr_purge_queue(cl);
qdisc_class_hash_remove(&q->clhash, &cl->common);
- if (--cl->refcnt == 0)
- drr_destroy_class(sch, cl);
+ BUG_ON(--cl->refcnt == 0);
+ /*
+ * This shouldn't happen: we "hold" one cops->get() when called
+ * from tc_ctl_tclass; the destroy method is done from cops->put().
+ */
sch_tree_unlock(sch);
return 0;
diff --git a/net/sched/sch_hfsc.c b/net/sched/sch_hfsc.c
index 74226b2..a516aa4 100644
--- a/net/sched/sch_hfsc.c
+++ b/net/sched/sch_hfsc.c
@@ -1139,8 +1139,11 @@ hfsc_delete_class(struct Qdisc *sch, unsigned long arg)
hfsc_purge_queue(sch, cl);
qdisc_class_hash_remove(&q->clhash, &cl->cl_common);
- if (--cl->refcnt == 0)
- hfsc_destroy_class(sch, cl);
+ BUG_ON(--cl->refcnt == 0);
+ /*
+ * This shouldn't happen: we "hold" one cops->get() when called
+ * from tc_ctl_tclass; the destroy method is done from cops->put().
+ */
sch_tree_unlock(sch);
return 0;
diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c
index 355974f..a4b682b 100644
--- a/net/sched/sch_htb.c
+++ b/net/sched/sch_htb.c
@@ -1275,8 +1275,11 @@ static int htb_delete(struct Qdisc *sch, unsigned long arg)
if (last_child)
htb_parent_to_leaf(q, cl, new_q);
- if (--cl->refcnt == 0)
- htb_destroy_class(sch, cl);
+ BUG_ON(--cl->refcnt == 0);
+ /*
+ * This shouldn't happen: we "hold" one cops->get() when called
+ * from tc_ctl_tclass; the destroy method is done from cops->put().
+ */
sch_tree_unlock(sch);
return 0;
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] pkt_sched: Change misleading code in class delete.
2009-03-15 12:35 ` [PATCH v2] " Jarek Poplawski
@ 2009-03-16 3:00 ` David Miller
0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2009-03-16 3:00 UTC (permalink / raw)
To: jarkao2; +Cc: m0sia, kaber, netdev
From: Jarek Poplawski <jarkao2@gmail.com>
Date: Sun, 15 Mar 2009 13:35:11 +0100
> While looking for a possible reason of bugzilla report on HTB oops:
> http://bugzilla.kernel.org/show_bug.cgi?id=12858
> I found the code in htb_delete calling htb_destroy_class on zero
> refcount is very misleading: it can suggest this is a common path, and
> destroy is called under sch_tree_lock. Actually, this can never happen
> like this because before deletion cops->get() is done, and after
> delete a class is still used by tclass_notify. The class destroy is
> always called from cops->put(), so without sch_tree_lock.
>
> This doesn't mean much now (since 2.6.27) because all vulnerable calls
> were moved from htb_destroy_class to htb_delete, but there was a bug
> in older kernels. The same change is done for other classful scheds,
> which, it seems, didn't have similar locking problems here.
>
> Reported-by: m0sia <m0sia@m0sia.ru>
> Signed-off-by: Jarek Poplawski <jarkao2@gmail.com>
Applied, thanks a lot Jarek.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-03-16 3:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-14 14:45 [PATCH] pkt_sched: Change misleading code in class delete Jarek Poplawski
2009-03-15 12:35 ` [PATCH v2] " Jarek Poplawski
2009-03-16 3:00 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).