netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
To: netdev@vger.kernel.org
Cc: edumazet@google.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com,
	jiri@resnulli.us, roopa@cumulusnetworks.com,
	Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Subject: [PATCH net 4/9] sch_hfsc: fix null pointer deref and double free on init failure
Date: Wed, 30 Aug 2017 12:49:00 +0300	[thread overview]
Message-ID: <1504086545-7777-5-git-send-email-nikolay@cumulusnetworks.com> (raw)
In-Reply-To: <1504086545-7777-1-git-send-email-nikolay@cumulusnetworks.com>

Depending on where ->init fails we can get a null pointer deref due to
uninitialized hires timer (watchdog) or a double free of the qdisc hash
because it is already freed by ->destroy().

Fixes: 8d5537387505 ("net/sched/hfsc: allocate tcf block for hfsc root class")
Fixes: 87b60cfacf9f ("net_sched: fix error recovery at qdisc creation")
Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
---
 net/sched/sch_hfsc.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/net/sched/sch_hfsc.c b/net/sched/sch_hfsc.c
index fd15200f8627..11ab8dace901 100644
--- a/net/sched/sch_hfsc.c
+++ b/net/sched/sch_hfsc.c
@@ -1418,6 +1418,8 @@ hfsc_init_qdisc(struct Qdisc *sch, struct nlattr *opt)
 	struct tc_hfsc_qopt *qopt;
 	int err;
 
+	qdisc_watchdog_init(&q->watchdog, sch);
+
 	if (opt == NULL || nla_len(opt) < sizeof(*qopt))
 		return -EINVAL;
 	qopt = nla_data(opt);
@@ -1430,7 +1432,7 @@ hfsc_init_qdisc(struct Qdisc *sch, struct nlattr *opt)
 
 	err = tcf_block_get(&q->root.block, &q->root.filter_list);
 	if (err)
-		goto err_tcf;
+		return err;
 
 	q->root.cl_common.classid = sch->handle;
 	q->root.refcnt  = 1;
@@ -1448,13 +1450,7 @@ hfsc_init_qdisc(struct Qdisc *sch, struct nlattr *opt)
 	qdisc_class_hash_insert(&q->clhash, &q->root.cl_common);
 	qdisc_class_hash_grow(sch, &q->clhash);
 
-	qdisc_watchdog_init(&q->watchdog, sch);
-
 	return 0;
-
-err_tcf:
-	qdisc_class_hash_destroy(&q->clhash);
-	return err;
 }
 
 static int
-- 
2.1.4

  parent reply	other threads:[~2017-08-30  9:49 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-30  9:48 [PATCH net 0/9] net/sched: init failure fixes Nikolay Aleksandrov
2017-08-30  9:48 ` [PATCH net 1/9] sch_htb: fix crash on init failure Nikolay Aleksandrov
2017-08-30  9:48 ` [PATCH net 2/9] sch_multiq: fix double free " Nikolay Aleksandrov
2017-08-30  9:48 ` [PATCH net 3/9] sch_hhf: fix null pointer dereference " Nikolay Aleksandrov
2017-08-30  9:49 ` Nikolay Aleksandrov [this message]
2017-08-30  9:49 ` [PATCH net 5/9] sch_cbq: fix null pointer dereferences " Nikolay Aleksandrov
2017-08-30  9:49 ` [PATCH net 6/9] sch_fq_codel: avoid double free " Nikolay Aleksandrov
2017-08-30 17:36   ` Cong Wang
2017-08-30 21:37     ` Nikolay Aleksandrov
2017-08-30  9:49 ` [PATCH net 7/9] sch_netem: avoid null pointer deref " Nikolay Aleksandrov
2017-08-30  9:49 ` [PATCH net 8/9] sch_sfq: fix null pointer dereference " Nikolay Aleksandrov
2017-08-30  9:49 ` [PATCH net 9/9] sch_tbf: fix two null pointer dereferences " Nikolay Aleksandrov
2017-08-30 17:37   ` Cong Wang
2017-08-30 21:39     ` Nikolay Aleksandrov
2017-08-30 12:15 ` [PATCH net 0/9] net/sched: init failure fixes Jamal Hadi Salim
2017-08-30 21:35   ` Nikolay Aleksandrov
2017-08-30 22:26   ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1504086545-7777-5-git-send-email-nikolay@cumulusnetworks.com \
    --to=nikolay@cumulusnetworks.com \
    --cc=edumazet@google.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=netdev@vger.kernel.org \
    --cc=roopa@cumulusnetworks.com \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).