Code inspection reveals that tipc_named_rcv() does not validate the original address of received packets. This can lead to two issues: 1. A remote peer can send a publication message whose original address is equal to the local node's address or is unknown. Upon receiving this message, the local node can follow this execution path: tipc_named_rcv() tipc_update_nametbl() tipc_nametbl_insert_publ() tipc_node_subscribe() return NULL; As a result, the inserted publication is not added to the local node's publ_list. Consequently, the publication will not be removed later when this list is traversed for publication removal. 2. A remote peer can send a withdrawal message whose original address is equal to the local node's address or is unknown. Upon receiving this message, the local node can follow this execution path: tipc_named_rcv() tipc_update_nametbl() tipc_nametbl_remove_publ() tipc_node_unsubscribe() return NULL; kfree_rcu(p, rcu); As a result, the publication is freed, but p->binding_node remains linked to the local node's publ_list. Subsequent traversal of this list will access freed memory. Fix these issues by validating the original address of received messages and rejecting those with invalid addresses. Fixes: b97bf3fd8f6a ("[TIPC] Initial merge") Signed-off-by: Tung Nguyen --- net/tipc/name_distr.c | 8 ++++++++ net/tipc/node.c | 34 ++++++++++++++++++++++++++-------- net/tipc/node.h | 1 + 3 files changed, 35 insertions(+), 8 deletions(-) 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