net: netrom: Fix potential nr_neigh refcnt leak in nr_add_node
authorXiyu Yang <xiyuyang19@fudan.edu.cn>
Wed, 15 Apr 2020 08:36:19 +0000 (16:36 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 2 May 2020 15:24:17 +0000 (17:24 +0200)
commitb8a15c1b91bb2e1a7feafa7ce6b0db6a8b762179
tree50294427db5cca76c132ffd4d80c3b0f5c6bf587
parent0388465ab6f945cab1d35eef4a83cc5823a82829
net: netrom: Fix potential nr_neigh refcnt leak in nr_add_node

[ Upstream commit d03f228470a8c0a22b774d1f8d47071e0de4f6dd ]

nr_add_node() invokes nr_neigh_get_dev(), which returns a local
reference of the nr_neigh object to "nr_neigh" with increased refcnt.

When nr_add_node() returns, "nr_neigh" becomes invalid, so the refcount
should be decreased to keep refcount balanced.

The issue happens in one normal path of nr_add_node(), which forgets to
decrease the refcnt increased by nr_neigh_get_dev() and causes a refcnt
leak. It should decrease the refcnt before the function returns like
other normal paths do.

Fix this issue by calling nr_neigh_put() before the nr_add_node()
returns.

Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/netrom/nr_route.c