Skip to content

Commit

Permalink
net/x25: Fix x25_neigh refcnt leak when x25 disconnect
Browse files Browse the repository at this point in the history
commit 4becb7e upstream.

x25_connect() invokes x25_get_neigh(), which returns a reference of the
specified x25_neigh object to "x25->neighbour" with increased refcnt.

When x25 connect success and returns, the reference still be hold by
"x25->neighbour", so the refcount should be decreased in
x25_disconnect() to keep refcount balanced.

The reference counting issue happens in x25_disconnect(), which forgets
to decrease the refcnt increased by x25_get_neigh() in x25_connect(),
causing a refcnt leak.

Fix this issue by calling x25_neigh_put() before x25_disconnect()
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>
  • Loading branch information
sherlly authored and gregkh committed Aug 5, 2020
1 parent c2fd34d commit 69cd304
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions net/x25/x25_subr.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,10 @@ void x25_disconnect(struct sock *sk, int reason, unsigned char cause,
sk->sk_state_change(sk);
sock_set_flag(sk, SOCK_DEAD);
}
read_lock_bh(&x25_list_lock);
x25_neigh_put(x25->neighbour);
x25->neighbour = NULL;
read_unlock_bh(&x25_list_lock);
}

/*
Expand Down

0 comments on commit 69cd304

Please sign in to comment.