net/x25: Fix x25_neigh refcnt leak when receiving frame
authorXiyu Yang <xiyuyang19@fudan.edu.cn>
Thu, 23 Apr 2020 05:13:03 +0000 (13:13 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Apr 2020 14:33:09 +0000 (16:33 +0200)
commit5a2ddf8e5a5d280fe9399d928db612bf1e4d3b03
tree89049bb28507536d52c8513c1a239b2422945ebe
parent6885d58eb4392b779d2de0616cfde6aa2e81d552
net/x25: Fix x25_neigh refcnt leak when receiving frame

[ Upstream commit f35d12971b4d814cdb2f659d76b42f0c545270b6 ]

x25_lapb_receive_frame() invokes x25_get_neigh(), which returns a
reference of the specified x25_neigh object to "nb" with increased
refcnt.

When x25_lapb_receive_frame() returns, local variable "nb" becomes
invalid, so the refcount should be decreased to keep refcount balanced.

The reference counting issue happens in one path of
x25_lapb_receive_frame(). When pskb_may_pull() returns false, the
function forgets to decrease the refcnt increased by x25_get_neigh(),
causing a refcnt leak.

Fix this issue by calling x25_neigh_put() when pskb_may_pull() returns
false.

Fixes: cb101ed2c3c7 ("x25: Handle undersized/fragmented skbs")
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/x25/x25_dev.c