summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorXiyu Yang <xiyuyang19@fudan.edu.cn>2020-04-25 21:06:25 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-08-05 10:06:02 +0200
commitfca9ee21e9777c8e0c59660a6af8e4b10f93b968 (patch)
tree03e0d0671b3cba3d54cd76e9fc762b2dbe31b1d2 /net
parentab6291837dcd31b595f1a867768cc73661a6da9e (diff)
net/x25: Fix x25_neigh refcnt leak when x25 disconnect
commit 4becb7ee5b3d2829ed7b9261a245a77d5b7de902 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>
Diffstat (limited to 'net')
-rw-r--r--net/x25/x25_subr.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/net/x25/x25_subr.c b/net/x25/x25_subr.c
index 743103786652..d34a874177d5 100644
--- a/net/x25/x25_subr.c
+++ b/net/x25/x25_subr.c
@@ -362,6 +362,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);
}
/*