Commit aa239369 authored by Nikita Yushchenko's avatar Nikita Yushchenko Committed by Greg Kroah-Hartman

net: dsa: fix unbalanced dsa_switch_tree reference counting

[ Upstream commit 7a99cd6e ]

_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().

Fixes: 83c0afae ("net: dsa: Add new binding implementation")
Signed-off-by: default avatarNikita Yushchenko <nikita.yoush@cogentembedded.com>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9a747927
...@@ -28,8 +28,10 @@ static struct dsa_switch_tree *dsa_get_dst(u32 tree) ...@@ -28,8 +28,10 @@ static struct dsa_switch_tree *dsa_get_dst(u32 tree)
struct dsa_switch_tree *dst; struct dsa_switch_tree *dst;
list_for_each_entry(dst, &dsa_switch_trees, list) list_for_each_entry(dst, &dsa_switch_trees, list)
if (dst->tree == tree) if (dst->tree == tree) {
kref_get(&dst->refcount);
return dst; return dst;
}
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment