Skip to content

Commit

Permalink
net/x25: Fix x25_neigh refcnt leak when receiving frame
Browse files Browse the repository at this point in the history
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: cb101ed ("x25: Handle undersized/fragmented skbs")
Signed-off-by: Xiyu Yang <[email protected]>
Signed-off-by: Xin Tan <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
sherlly authored and davem330 committed Apr 23, 2020
1 parent b4e0f9a commit f35d129
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion net/x25/x25_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ int x25_lapb_receive_frame(struct sk_buff *skb, struct net_device *dev,
goto drop;
}

if (!pskb_may_pull(skb, 1))
if (!pskb_may_pull(skb, 1)) {
x25_neigh_put(nb);
return 0;
}

switch (skb->data[0]) {

Expand Down

0 comments on commit f35d129

Please sign in to comment.