Skip to contentSkip to conversation

tipc: fix NULL deref in tipc_named_node_up() on empty publication list

PATCH Superseded Weiming Shi 2 participants 4 messages Jul 6 – Jul 14

Subsystems (3)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tipc: fix NULL deref in tipc_named_node_up() on empty publication list

named_distribute() builds the bulk messages for @pls into @list and then dereferences the tail skb:

	hdr = buf_msg(skb_peek_tail(list));
	msg_set_last_bulk(hdr);

If @pls is empty no skb is enqueued, skb_peek_tail() returns NULL, and msg_set_last_bulk() writes through buf_msg(NULL).

tipc_named_node_up() passes &nt->cluster_scope. With a node-id configuration the TIPC_NODE_STATE name is published by tipc_net_finalize() from a work item, which sets the node address before publishing the name. The node accepts links once the address is set, so a link that comes up before the publish runs named_distribute() on an empty cluster_scope:

 KASAN: null-ptr-deref in range [0x00000000000000d8-0x00000000000000df]
 RIP: 0010:tipc_named_node_up (net/tipc/name_distr.c:196)
  tipc_named_node_up (net/tipc/name_distr.c:196 net/tipc/name_distr.c:221)
  tipc_node_write_unlock (net/tipc/node.c:428)
  tipc_rcv (net/tipc/node.c:2185)
  tipc_udp_recv (net/tipc/udp_media.c:392)
 Kernel panic - not syncing: Fatal exception in interrupt

TIPC genl ops use GENL_UNS_ADMIN_PERM, so an unprivileged user can reach this from a user+net namespace.

Return early in tipc_named_node_up() when cluster_scope is empty, so named_distribute() is not called with an empty list.

Fixes cad2929dc432 ("tipc: update a binding service via broadcast")
Assisted-by Claude:claude-opus-4-8

---
v2:
- Return early in tipc_named_node_up() when cluster_scope is empty, instead of guarding the tail access inside named_distribute().

 net/tipc/name_distr.c | 4 ++++
 1 file changed, 4 insertions(+)
net/tipc/name_distr.c +4 -0
index ba4f4906e13b..60ccaa862162 100644
@@ -218,6 +218,10 @@ void tipc_named_node_up(struct net *net, u32 dnode, u16 capabilities)
 	spin_unlock_bh(&tn->nametbl_lock);
 
 	read_lock_bh(&nt->cluster_scope_lock);
+	if (list_empty(&nt->cluster_scope)) {
+		read_unlock_bh(&nt->cluster_scope_lock);
+		return;
+	}
 	named_distribute(net, &head, dnode, &nt->cluster_scope, seqno);
 	tipc_node_xmit(net, &head, dnode, 0);
 	read_unlock_bh(&nt->cluster_scope_lock);
Signature · 1 line
2.43.0
reviewer
#1 lore raw

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev
---
tipc: fix NULL deref in tipc_named_node_up() on empty publication list

This commit fixes a NULL pointer dereference in tipc_named_node_up() that occurs when the cluster_scope publication list is empty. The fix introduces an early return to avoid calling named_distribute() with an empty list.

net/tipc/name_distr.c void tipc_named_node_up(struct net *net, u32 dnode, u16 capabilities) · line 224

Quoted 12 lines
net/tipc/name_distr.c +4 -0
index ba4f4906e13b7..60ccaa862162c 100644
@@ -218,6 +218,10 @@ void tipc_named_node_up(struct net *net, u32 dnode, u16 capabilities)
 	spin_unlock_bh(&tn->nametbl_lock);
 
 	read_lock_bh(&nt->cluster_scope_lock);
+	if (list_empty(&nt->cluster_scope)) {
+		read_unlock_bh(&nt->cluster_scope_lock);
+		return;
+	}

[Severity: Critical]
Does this early return prevent the transmission of the last_bulk synchronization message to the peer node?

In tipc_named_dequeue(), the peer node sets *open = true only when receiving a message where msg_is_last_bulk(hdr) is true:

net/tipc/name_distr.c:tipc_named_dequeue() {
        ...
        if (*open && (*rcv_nxt == seqno)) {
                (*rcv_nxt)++;
                __skb_unlink(skb, namedq);
                ...
                return skb;
        }
        ...
}

If *open is false, all subsequent non-bulk name publications will fail this sequence check and remain in the namedq indefinitely.

Without sending the last_bulk message, could this cause a permanent stall of name table updates and an unbounded memory leak of socket buffers on the peer node?

net/tipc/name_distr.c void tipc_named_node_up(struct net *net, u32 dnode, u16 capabilities) · line 225

Quoted 1 line
net/tipc/name_distr.c +0 -0
 	named_distribute(net, &head, dnode, &nt->cluster_scope, seqno);

[Severity: High]
This isn't a bug introduced by this patch, but looking at named_distribute() called here, what happens if buffer allocation fails during the loop?

Inside named_distribute():

net/tipc/name_distr.c:named_distribute() {
        ...
        if (!skb) {
                skb = named_prepare_buf(net, PUBLICATION, msg_rem, dnode);
                if (!skb) {
                        pr_warn("Bulk publication failure\n");
                        return;
                }
        ...
}

If the function returns early due to allocation failure, the messages already added to the queue are transmitted by tipc_node_xmit(), but none of them will have the last_bulk flag set since that happens at the very end of the function.

Could this also prevent the receiving node from transitioning its named_open state to true, leading to the exact same permanent stall and memory leak of subsequent normal name publications?

Quoted 2 lines
net/tipc/name_distr.c +0 -0
 	tipc_node_xmit(net, &head, dnode, 0);
 	read_unlock_bh(&nt->cluster_scope_lock);
reviewer
#2 lore raw
In reply to Weiming Shi

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev
---
tipc: fix NULL deref in tipc_named_node_up() on empty publication list

This commit fixes a NULL pointer dereference in tipc_named_node_up() that occurs when the cluster_scope publication list is empty. The fix introduces an early return to avoid calling named_distribute() with an empty list.

net/tipc/name_distr.c void tipc_named_node_up(struct net *net, u32 dnode, u16 capabilities) · line 224

Quoted 12 lines
net/tipc/name_distr.c +4 -0
index ba4f4906e13b7..60ccaa862162c 100644
@@ -218,6 +218,10 @@ void tipc_named_node_up(struct net *net, u32 dnode, u16 capabilities)
 	spin_unlock_bh(&tn->nametbl_lock);
 
 	read_lock_bh(&nt->cluster_scope_lock);
+	if (list_empty(&nt->cluster_scope)) {
+		read_unlock_bh(&nt->cluster_scope_lock);
+		return;
+	}

[Severity: Critical]
Does this early return prevent the transmission of the last_bulk synchronization message to the peer node?

In tipc_named_dequeue(), the peer node sets *open = true only when receiving a message where msg_is_last_bulk(hdr) is true:

net/tipc/name_distr.c:tipc_named_dequeue() {
        ...
        if (*open && (*rcv_nxt == seqno)) {
                (*rcv_nxt)++;
                __skb_unlink(skb, namedq);
                ...
                return skb;
        }
        ...
}

If *open is false, all subsequent non-bulk name publications will fail this sequence check and remain in the namedq indefinitely.

Without sending the last_bulk message, could this cause a permanent stall of name table updates and an unbounded memory leak of socket buffers on the peer node?

net/tipc/name_distr.c void tipc_named_node_up(struct net *net, u32 dnode, u16 capabilities) · line 225

Quoted 1 line
net/tipc/name_distr.c +0 -0
 	named_distribute(net, &head, dnode, &nt->cluster_scope, seqno);

[Severity: High]
This isn't a bug introduced by this patch, but looking at named_distribute() called here, what happens if buffer allocation fails during the loop?

Inside named_distribute():

net/tipc/name_distr.c:named_distribute() {
        ...
        if (!skb) {
                skb = named_prepare_buf(net, PUBLICATION, msg_rem, dnode);
                if (!skb) {
                        pr_warn("Bulk publication failure\n");
                        return;
                }
        ...
}

If the function returns early due to allocation failure, the messages already added to the queue are transmitted by tipc_node_xmit(), but none of them will have the last_bulk flag set since that happens at the very end of the function.

Could this also prevent the receiving node from transitioning its named_open state to true, leading to the exact same permanent stall and memory leak of subsequent normal name publications?

Quoted 2 lines
net/tipc/name_distr.c +0 -0
 	tipc_node_xmit(net, &head, dnode, 0);
 	read_unlock_bh(&nt->cluster_scope_lock);
Signature · 1 line
pw-bot: changes-requested
#3 lore raw
Quoted 73 lines · Simon Horman <[email protected]> 于2026年7月13日周一 21:46写道:

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev
---
tipc: fix NULL deref in tipc_named_node_up() on empty publication list

This commit fixes a NULL pointer dereference in tipc_named_node_up() that occurs when the cluster_scope publication list is empty. The fix introduces an early return to avoid calling named_distribute() with an empty list.

net/tipc/name_distr.c void tipc_named_node_up(struct net *net, u32 dnode, u16 capabilities) · line 224

Quoted 12 lines
net/tipc/name_distr.c +4 -0
index ba4f4906e13b7..60ccaa862162c 100644
@@ -218,6 +218,10 @@ void tipc_named_node_up(struct net *net, u32 dnode, u16 capabilities)
      spin_unlock_bh(&tn->nametbl_lock);
 
      read_lock_bh(&nt->cluster_scope_lock);
+     if (list_empty(&nt->cluster_scope)) {
+             read_unlock_bh(&nt->cluster_scope_lock);
+             return;
+     }

[Severity: Critical]
Does this early return prevent the transmission of the last_bulk synchronization message to the peer node?

In tipc_named_dequeue(), the peer node sets *open = true only when receiving a message where msg_is_last_bulk(hdr) is true:

net/tipc/name_distr.c:tipc_named_dequeue() {
        ...
        if (*open && (*rcv_nxt == seqno)) {
                (*rcv_nxt)++;
                __skb_unlink(skb, namedq);
                ...
                return skb;
        }
        ...
}

If *open is false, all subsequent non-bulk name publications will fail this sequence check and remain in the namedq indefinitely.

Without sending the last_bulk message, could this cause a permanent stall of name table updates and an unbounded memory leak of socket buffers on the peer node?

net/tipc/name_distr.c void tipc_named_node_up(struct net *net, u32 dnode, u16 capabilities) · line 225

Quoted 1 line
net/tipc/name_distr.c +0 -0
      named_distribute(net, &head, dnode, &nt->cluster_scope, seqno);

[Severity: High]
This isn't a bug introduced by this patch, but looking at named_distribute() called here, what happens if buffer allocation fails during the loop?

Inside named_distribute():

net/tipc/name_distr.c:named_distribute() {
        ...
        if (!skb) {
                skb = named_prepare_buf(net, PUBLICATION, msg_rem, dnode);
                if (!skb) {
                        pr_warn("Bulk publication failure\n");
                        return;
                }
        ...
}

If the function returns early due to allocation failure, the messages already added to the queue are transmitted by tipc_node_xmit(), but none of them will have the last_bulk flag set since that happens at the very end of the function.

Quoted 8 lines

Could this also prevent the receiving node from transitioning its named_open state to true, leading to the exact same permanent stall and memory leak of subsequent normal name publications?

net/tipc/name_distr.c void tipc_named_node_up(struct net *net, u32 dnode, u16 capabilities) · line 227

Quoted 2 lines
net/tipc/name_distr.c +0 -0
      tipc_node_xmit(net, &head, dnode, 0);
      read_unlock_bh(&nt->cluster_scope_lock);

--
pw-bot: changes-requested

Hi ,
Thank you for the review and feedback. v3 sent.