Commit de058420 authored by Xiyu Yang's avatar Xiyu Yang Committed by David S. Miller

tipc: Fix potential tipc_node refcnt leak in tipc_rcv

tipc_rcv() invokes tipc_node_find() twice, which returns a reference of
the specified tipc_node object to "n" with increased refcnt.

When tipc_rcv() returns or a new object is assigned to "n", the original
local reference of "n" becomes invalid, so the refcount should be
decreased to keep refcount balanced.

The issue happens in some paths of tipc_rcv(), which forget to decrease
the refcnt increased by tipc_node_find() and will cause a refcnt leak.

Fix this issue by calling tipc_node_put() before the original object
pointed by "n" becomes invalid.
Signed-off-by: default avatarXiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: default avatarXin Tan <tanxin.ctf@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 441870ee
...@@ -2038,6 +2038,7 @@ void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b) ...@@ -2038,6 +2038,7 @@ void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b)
n = tipc_node_find_by_id(net, ehdr->id); n = tipc_node_find_by_id(net, ehdr->id);
} }
tipc_crypto_rcv(net, (n) ? n->crypto_rx : NULL, &skb, b); tipc_crypto_rcv(net, (n) ? n->crypto_rx : NULL, &skb, b);
tipc_node_put(n);
if (!skb) if (!skb)
return; return;
...@@ -2090,7 +2091,7 @@ void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b) ...@@ -2090,7 +2091,7 @@ void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b)
/* Check/update node state before receiving */ /* Check/update node state before receiving */
if (unlikely(skb)) { if (unlikely(skb)) {
if (unlikely(skb_linearize(skb))) if (unlikely(skb_linearize(skb)))
goto discard; goto out_node_put;
tipc_node_write_lock(n); tipc_node_write_lock(n);
if (tipc_node_check_state(n, skb, bearer_id, &xmitq)) { if (tipc_node_check_state(n, skb, bearer_id, &xmitq)) {
if (le->link) { if (le->link) {
...@@ -2119,6 +2120,7 @@ void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b) ...@@ -2119,6 +2120,7 @@ void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b)
if (!skb_queue_empty(&xmitq)) if (!skb_queue_empty(&xmitq))
tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr, n); tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr, n);
out_node_put:
tipc_node_put(n); tipc_node_put(n);
discard: discard:
kfree_skb(skb); kfree_skb(skb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment