Skip to contentSkip to conversation

net_sched: prevent NULL dereference if default qdisc setup failed

PATCH Applied Pratyush Yadav 2 participants 2 messages Apr 11, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net_sched: prevent NULL dereference if default qdisc setup failed

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")

---

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(+)
net/sched/sch_generic.c +1 -0
index 1f055c21be4cf..4250f3cf30e72 100644
@@ -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

maintainer Applied
#1 lore raw

Patch "net_sched: prevent NULL dereference if default qdisc setup failed" has been added to the 5.4-stable tree

This is a note to let you know that I've just added the patch titled

net_sched: prevent NULL dereference if default qdisc setup failed

to the 5.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
net_sched-prevent-null-dereference-if-default-qdisc-setup-failed.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

From [email protected] Tue Apr 11 15:12:32 2023
From: Pratyush Yadav <[email protected]>
Date: Tue, 11 Apr 2023 15:02:10 +0200
Subject: net_sched: prevent NULL dereference if default qdisc setup failed
To: Greg Kroah-Hartman <[email protected]>
Cc: Pratyush Yadav <[email protected]>, <[email protected]>, <[email protected]>, Eric Dumazet <[email protected]>, Vlad Buslov <[email protected]>, syzbot <[email protected]>, Jamal Hadi Salim <[email protected]>, Cong Wang <[email protected]>, Jiri Pirko <[email protected]>, "David S. Miller" <[email protected]>, Zubin Mithra <[email protected]>, Norbert Manthey <[email protected]>
Message-ID: <[email protected]>

From: Pratyush Yadav <[email protected]>

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")
---
 net/sched/sch_generic.c |    1 +
 1 file changed, 1 insertion(+)
net/sched/sch_generic.c +1 -0
@@ -1116,6 +1116,7 @@ static void attach_default_qdiscs(struct
 			qdisc->ops->attach(qdisc);
 		}
 	}
+	qdisc = rtnl_dereference(dev->qdisc);
 
 #ifdef CONFIG_NET_SCHED
 	if (qdisc != &noop_qdisc)

Patches currently in stable-queue which might be from [email protected] are

queue-5.4/net_sched-prevent-null-dereference-if-default-qdisc-setup-failed.patch queue-5.4/smb3-fix-problem-with-null-cifs-super-block-with-previous-patch.patch