Archive-only list for patches
 help / color / mirror / Atom feed
* [PATCH 5.4] net_sched: prevent NULL dereference if default qdisc setup failed
@ 2023-04-11 13:02 Pratyush Yadav
  2023-04-11 13:14 ` Patch "net_sched: prevent NULL dereference if default qdisc setup failed" has been added to the 5.4-stable tree gregkh
  0 siblings, 1 reply; 2+ messages in thread
From: Pratyush Yadav @ 2023-04-11 13:02 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Pratyush Yadav, stable, patches, Eric Dumazet, Vlad Buslov,
	syzbot, Jamal Hadi Salim, Cong Wang, Jiri Pirko, David S. Miller,
	Zubin Mithra, Norbert Manthey

If qdisc_create_dflt() fails, it returns NULL. With CONFIG_NET_SCHED
enabled, the check qdisc != &noop_qdisc passes and qdisc will be passed
to qdisc_hash_add(), which dereferences it.

This assignment was present in the upstream commit
5891cd5ec46c2 ("net_sched: add __rcu annotation to netdev->qdisc") but
was missed in the backport 22d95b5449249 ("net_sched: add __rcu
annotation to netdev->qdisc"), perhaps due to merge conflicts.
dev->qdisc is &noop_qdisc by default and if qdisc_create_dflt() fails,
this assignment will make sure qdisc == &noop_qdisc and no NULL
dereference will take place.

This bug was discovered and resolved using Coverity Static Analysis
Security Testing (SAST) by Synopsys, Inc.

Fixes: 22d95b5449249 ("net_sched: add __rcu annotation to netdev->qdisc")
Signed-off-by: Pratyush Yadav <ptyadav@amazon.de>
---

As usual, this was found by our static code analysis bot. I have
compile-tested this patch and ran a simple boot test. Did not do any
testing specifically to hit this bug.

 net/sched/sch_generic.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
index 1f055c21be4cf..4250f3cf30e72 100644
--- a/net/sched/sch_generic.c
+++ b/net/sched/sch_generic.c
@@ -1116,6 +1116,7 @@ static void attach_default_qdiscs(struct net_device *dev)
 			qdisc->ops->attach(qdisc);
 		}
 	}
+	qdisc = rtnl_dereference(dev->qdisc);

 #ifdef CONFIG_NET_SCHED
 	if (qdisc != &noop_qdisc)
--
2.39.2


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

end of thread, other threads:[~2023-04-11 13:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-11 13:02 [PATCH 5.4] net_sched: prevent NULL dereference if default qdisc setup failed Pratyush Yadav
2023-04-11 13:14 ` Patch "net_sched: prevent NULL dereference if default qdisc setup failed" has been added to the 5.4-stable tree gregkh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox