netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch net] net_sched: fix error path in red_init()
@ 2020-08-27 17:40 Cong Wang
  2020-08-28 11:08 ` Petr Machata
  2020-08-28 14:17 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Cong Wang @ 2020-08-27 17:40 UTC (permalink / raw)
  To: netdev
  Cc: Cong Wang, syzbot+b33c1cb0a30ebdc8a5f9,
	syzbot+e5ea5f8a3ecfd4427a1c, Petr Machata

When ->init() fails, ->destroy() is called to clean up.
So it is unnecessary to clean up in red_init(), and it
would cause some refcount underflow.

Fixes: aee9caa03fc3 ("net: sched: sch_red: Add qevents "early_drop" and "mark"")
Reported-and-tested-by: syzbot+b33c1cb0a30ebdc8a5f9@syzkaller.appspotmail.com
Reported-and-tested-by: syzbot+e5ea5f8a3ecfd4427a1c@syzkaller.appspotmail.com
Cc: Petr Machata <petrm@mellanox.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
 net/sched/sch_red.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/net/sched/sch_red.c b/net/sched/sch_red.c
index deac82f3ad7b..e89fab6ccb34 100644
--- a/net/sched/sch_red.c
+++ b/net/sched/sch_red.c
@@ -353,23 +353,11 @@ static int red_init(struct Qdisc *sch, struct nlattr *opt,
 			      FLOW_BLOCK_BINDER_TYPE_RED_EARLY_DROP,
 			      tb[TCA_RED_EARLY_DROP_BLOCK], extack);
 	if (err)
-		goto err_early_drop_init;
-
-	err = tcf_qevent_init(&q->qe_mark, sch,
-			      FLOW_BLOCK_BINDER_TYPE_RED_MARK,
-			      tb[TCA_RED_MARK_BLOCK], extack);
-	if (err)
-		goto err_mark_init;
-
-	return 0;
+		return err;
 
-err_mark_init:
-	tcf_qevent_destroy(&q->qe_early_drop, sch);
-err_early_drop_init:
-	del_timer_sync(&q->adapt_timer);
-	red_offload(sch, false);
-	qdisc_put(q->qdisc);
-	return err;
+	return tcf_qevent_init(&q->qe_mark, sch,
+			       FLOW_BLOCK_BINDER_TYPE_RED_MARK,
+			       tb[TCA_RED_MARK_BLOCK], extack);
 }
 
 static int red_change(struct Qdisc *sch, struct nlattr *opt,
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Patch net] net_sched: fix error path in red_init()
  2020-08-27 17:40 [Patch net] net_sched: fix error path in red_init() Cong Wang
@ 2020-08-28 11:08 ` Petr Machata
  2020-08-28 14:17 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Petr Machata @ 2020-08-28 11:08 UTC (permalink / raw)
  To: Cong Wang
  Cc: netdev, syzbot+b33c1cb0a30ebdc8a5f9, syzbot+e5ea5f8a3ecfd4427a1c,
	Petr Machata


Cong Wang <xiyou.wangcong@gmail.com> writes:

> When ->init() fails, ->destroy() is called to clean up.
> So it is unnecessary to clean up in red_init(), and it
> would cause some refcount underflow.

Hmm, yeah, qdisc_put() would get called twice. A surprising API, the
init needs to make sure to always bring the qdisc into destroyable
state. But qevents are like that after kzalloc, so the fix looks
correct.

Reviewed-by: Petr Machata <petrm@nvidia.com>

Thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch net] net_sched: fix error path in red_init()
  2020-08-27 17:40 [Patch net] net_sched: fix error path in red_init() Cong Wang
  2020-08-28 11:08 ` Petr Machata
@ 2020-08-28 14:17 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2020-08-28 14:17 UTC (permalink / raw)
  To: xiyou.wangcong
  Cc: netdev, syzbot+b33c1cb0a30ebdc8a5f9, syzbot+e5ea5f8a3ecfd4427a1c,
	petrm

From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Thu, 27 Aug 2020 10:40:41 -0700

> When ->init() fails, ->destroy() is called to clean up.
> So it is unnecessary to clean up in red_init(), and it
> would cause some refcount underflow.
> 
> Fixes: aee9caa03fc3 ("net: sched: sch_red: Add qevents "early_drop" and "mark"")
> Reported-and-tested-by: syzbot+b33c1cb0a30ebdc8a5f9@syzkaller.appspotmail.com
> Reported-and-tested-by: syzbot+e5ea5f8a3ecfd4427a1c@syzkaller.appspotmail.com
> Cc: Petr Machata <petrm@mellanox.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>

Applied, thank you.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-08-28 14:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-27 17:40 [Patch net] net_sched: fix error path in red_init() Cong Wang
2020-08-28 11:08 ` Petr Machata
2020-08-28 14:17 ` 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).