Skip to contentSkip to conversation

net_sched: avoid matching qdisc with zero handle

PATCH In review Cong Wang 2 participants 2 messages Oct 28, 2017 – Oct 29, 2017

Subsystems (3)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 net_sched: avoid matching qdisc with zero handle

Davide found the following script triggers a NULL pointer dereference:

ip l a name eth0 type dummy
tc q a dev eth0 parent :1 handle 1: htb

This is because for a freshly created netdevice noop_qdisc is attached and when passing 'parent :1', kernel actually tries to match the major handle which is 0 and noop_qdisc has handle 0 so is matched by mistake. Commit 69012ae425d7 tries to fix a similar bug but still misses this case.

Handle 0 is not a valid one, should be just skipped. In fact, kernel uses it as TC_H_UNSPEC.

Fixes 69012ae425d7 ("net: sched: fix handling of singleton qdiscs with qdisc_hash")
Fixes 59cc1f61f09c ("net: sched:convert qdisc linked list to hashtable")
Cc Jiri Kosina <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jamal Hadi Salim <[email protected]>
---
 net/sched/sch_api.c | 2 ++
 1 file changed, 2 insertions(+)
net/sched/sch_api.c +2 -0
index c6deb74e3d2f..22bc6fc48311 100644
@@ -301,6 +301,8 @@ struct Qdisc *qdisc_lookup(struct net_device *dev, u32 handle)
 {
 	struct Qdisc *q;
 
+	if (!handle)
+		return NULL;
 	q = qdisc_match_from_root(dev->qdisc, handle);
 	if (q)
 		goto out;
Signature · 1 line
2.13.0
maintainer
#1 lore raw

From: Cong Wang <[email protected]>
Date: Fri, 27 Oct 2017 22:08:56 -0700

Quoted 15 lines

Davide found the following script triggers a NULL pointer dereference:

ip l a name eth0 type dummy
tc q a dev eth0 parent :1 handle 1: htb

This is because for a freshly created netdevice noop_qdisc is attached and when passing 'parent :1', kernel actually tries to match the major handle which is 0 and noop_qdisc has handle 0 so is matched by mistake. Commit 69012ae425d7 tries to fix a similar bug but still misses this case.

Handle 0 is not a valid one, should be just skipped. In fact, kernel uses it as TC_H_UNSPEC.

Quoted 7 lines
Fixes 69012ae425d7 ("net: sched: fix handling of singleton qdiscs with qdisc_hash")
Fixes 59cc1f61f09c ("net: sched:convert qdisc linked list to hashtable")
Cc Jiri Kosina <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jamal Hadi Salim <[email protected]>

Applied and queued up for -stable, thanks.