Patch "net: dsa: fix unbalanced dsa_switch_tree reference counting" has been added to the 4.8-stable tree
Subsystems (3)
This is a note to let you know that I've just added the patch titled
net: dsa: fix unbalanced dsa_switch_tree reference counting
to the 4.8-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-dsa-fix-unbalanced-dsa_switch_tree-reference-counting.patch
and it can be found in the queue-4.8 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From foo@baz Thu Dec 8 07:19:12 CET 2016
From: Nikita Yushchenko <[email protected]>
Date: Mon, 28 Nov 2016 09:48:48 +0300
Subject: net: dsa: fix unbalanced dsa_switch_tree reference counting
From: Nikita Yushchenko <[email protected]>
[ Upstream commit 7a99cd6e213685b78118382e6a8fed506c82ccb2 ]
_dsa_register_switch() gets a dsa_switch_tree object either via dsa_get_dst() or via dsa_add_dst(). Former path does not increase kref in returned object (resulting into caller not owning a reference), while later path does create a new object (resulting into caller owning a reference).
The rest of _dsa_register_switch() assumes that it owns a reference, and calls dsa_put_dst().
This causes a memory breakage if first switch in the tree initialized successfully, but second failed to initialize. In particular, freed dsa_swith_tree object is left referenced by switch that was initialized, and later access to sysfs attributes of that switch cause OOPS.
To fix, need to add kref_get() call to dsa_get_dst().
--- net/dsa/dsa2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/dsa/dsa2.c +3 -1
@@ -28,8 +28,10 @@ static struct dsa_switch_tree *dsa_get_dstruct dsa_switch_tree *dst;list_for_each_entry (dst, &dsa_switch_trees, list) -if (dst->tree == tree) +if (dst->tree == tree) { +kref_get (&dst->refcount);return dst; + }return NULL ; }
Patches currently in stable-queue which might be from [email protected] are
queue-4.8/net-dsa-fix-unbalanced-dsa_switch_tree-reference-counting.patch