Skip to content

Commit

Permalink
net: netrom: Fix potential nr_neigh refcnt leak in nr_add_node
Browse files Browse the repository at this point in the history
[ Upstream commit d03f228 ]

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 <[email protected]>
Signed-off-by: Xin Tan <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
sherlly authored and gregkh committed Apr 29, 2020
1 parent befd63a commit 21b1a76
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions net/netrom/nr_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ static int __must_check nr_add_node(ax25_address *nr, const char *mnemonic,
/* refcount initialized at 1 */
spin_unlock_bh(&nr_node_list_lock);

nr_neigh_put(nr_neigh);
return 0;
}
nr_node_lock(nr_node);
Expand Down

0 comments on commit 21b1a76

Please sign in to comment.