diff --git a/net/tipc/name_distr.c b/net/tipc/name_distr.c
index 3ea5e900cb45..1fe650a95eb4 100644
--- a/net/tipc/name_distr.c
+++ b/net/tipc/name_distr.c
@@ -378,18 +378,26 @@ void tipc_named_rcv(struct net *net, struct sk_buff_head *namedq,
struct distr_item *item;
struct tipc_msg *hdr;
struct sk_buff *skb;
+ struct tipc_node *n;
u32 count, node;
spin_lock_bh(&tn->nametbl_lock);
while ((skb = tipc_named_dequeue(namedq, rcv_nxt, open))) {
hdr = buf_msg(skb);
node = msg_orignode(hdr);
+ n = tipc_node_find_remote(net, node);
+ if (!n)
+ goto free_skb;
+ else
+ tipc_node_put(n);
+
item = (struct distr_item *)msg_data(hdr);
count = msg_data_sz(hdr) / ITEM_SIZE;
while (count--) {
tipc_update_nametbl(net, item, node, msg_type(hdr));
item++;
}
+free_skb:
kfree_skb(skb);
}
spin_unlock_bh(&tn->nametbl_lock);diff --git a/net/tipc/node.c b/net/tipc/node.c
index 870f84e2fb1c..dfbeed21dbc1 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -657,16 +657,37 @@ void tipc_node_stop(struct net *net)
spin_unlock_bh(&tn->node_list_lock);
}
-void tipc_node_subscribe(struct net *net, struct list_head *subscr, u32 addr)
+/**
+ * tipc_node_find_remote - Find a node associated with an address
+ * @net: the associated network namespace
+ * @addr: node's address
+ *
+ * Return:
+ * * Found node - Success
+ * * NULL - Invalid node's address
+ *
+ */
+struct tipc_node *tipc_node_find_remote(struct net *net, u32 addr)
{
struct tipc_node *n;
if (in_own_node(net, addr))
- return;
+ return NULL;
n = tipc_node_find(net, addr);
+ if (!n)
+ return NULL;
+
+ return n;
+}
+
+void tipc_node_subscribe(struct net *net, struct list_head *subscr, u32 addr)
+{
+ struct tipc_node *n;
+
+ n = tipc_node_find_remote(net, addr);
if (!n) {
- pr_warn("Node subscribe rejected, unknown node 0x%x\n", addr);
+ pr_warn("Node subscribe rejected, invalid node 0x%x\n", addr);
return;
}
tipc_node_write_lock(n);@@ -679,12 +700,9 @@ void tipc_node_unsubscribe(struct net *net, struct list_head *subscr, u32 addr)
{
struct tipc_node *n;
- if (in_own_node(net, addr))
- return;
-
- n = tipc_node_find(net, addr);
+ n = tipc_node_find_remote(net, addr);
if (!n) {
- pr_warn("Node unsubscribe rejected, unknown node 0x%x\n", addr);
+ pr_warn("Node unsubscribe rejected, invalid node 0x%x\n", addr);
return;
}
tipc_node_write_lock(n);diff --git a/net/tipc/node.h b/net/tipc/node.h
index 154a5bbb0d29..411fac8c00ce 100644
--- a/net/tipc/node.h
+++ b/net/tipc/node.h
@@ -103,6 +103,7 @@ int tipc_node_xmit(struct net *net, struct sk_buff_head *list, u32 dnode,
int tipc_node_distr_xmit(struct net *net, struct sk_buff_head *list);
int tipc_node_xmit_skb(struct net *net, struct sk_buff *skb, u32 dest,
u32 selector);
+struct tipc_node *tipc_node_find_remote(struct net *net, u32 addr);
void tipc_node_subscribe(struct net *net, struct list_head *subscr, u32 addr);
void tipc_node_unsubscribe(struct net *net, struct list_head *subscr, u32 addr);
void tipc_node_broadcast(struct net *net, struct sk_buff *skb, int rc_dests);
--
2.53.0