Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net/x25: Fix x25_neigh refcnt leak when receiving frame

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>

authored by

Xiyu Yang and committed by
David S. Miller
f35d1297 b4e0f9a9

+3 -1
+3 -1
net/x25/x25_dev.c
··· 115 115 goto drop; 116 116 } 117 117 118 - if (!pskb_may_pull(skb, 1)) 118 + if (!pskb_may_pull(skb, 1)) { 119 + x25_neigh_put(nb); 119 120 return 0; 121 + } 120 122 121 123 switch (skb->data[0]) { 122 124