Skip to content

Commit 944d671

Browse files
wyjwangdavem330
authored andcommitted
sch_htb: fix refcount leak in htb_parent_to_leaf_offload
The commit ae81feb ("sch_htb: fix null pointer dereference on a null new_q") fixes a NULL pointer dereference bug, but it is not correct. Because htb_graft_helper properly handles the case when new_q is NULL, and after the previous patch by skipping this call which creates an inconsistency : dev_queue->qdisc will still point to the old qdisc, but cl->parent->leaf.q will point to the new one (which will be noop_qdisc, because new_q was NULL). The code is based on an assumption that these two pointers are the same, so it can lead to refcount leaks. The correct fix is to add a NULL pointer check to protect qdisc_refcount_inc inside htb_parent_to_leaf_offload. Fixes: ae81feb ("sch_htb: fix null pointer dereference on a null new_q") Signed-off-by: Yunjian Wang <[email protected]> Suggested-by: Maxim Mikityanskiy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 26821ec commit 944d671

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

net/sched/sch_htb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,8 @@ static void htb_parent_to_leaf_offload(struct Qdisc *sch,
14881488
struct Qdisc *old_q;
14891489

14901490
/* One ref for cl->leaf.q, the other for dev_queue->qdisc. */
1491-
qdisc_refcount_inc(new_q);
1491+
if (new_q)
1492+
qdisc_refcount_inc(new_q);
14921493
old_q = htb_graft_helper(dev_queue, new_q);
14931494
WARN_ON(!(old_q->flags & TCQ_F_BUILTIN));
14941495
}
@@ -1675,10 +1676,9 @@ static int htb_delete(struct Qdisc *sch, unsigned long arg,
16751676
cl->parent->common.classid,
16761677
NULL);
16771678
if (q->offload) {
1678-
if (new_q) {
1679+
if (new_q)
16791680
htb_set_lockdep_class_child(new_q);
1680-
htb_parent_to_leaf_offload(sch, dev_queue, new_q);
1681-
}
1681+
htb_parent_to_leaf_offload(sch, dev_queue, new_q);
16821682
}
16831683
}
16841684

0 commit comments

Comments
 (0)