* [PATCH net] tipc: don't update capabilities from duplicate discovery requests
@ 2026-11-29 0:17 Andrew Stellman
2026-11-30 8:20 ` Tung Quang Nguyen
0 siblings, 1 reply; 2+ messages in thread
From: Andrew Stellman @ 2026-11-29 0:17 UTC (permalink / raw)
To: Jon Maloy, Tung Quang Nguyen
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, netdev, tipc-discussion, linux-kernel
From: Andrew Stellman <astellman@stellman-greene.com>
tipc_node_check_dest() calls tipc_node_create() before it classifies a
discovery request. For an established node, found by node address or
by peer ID, tipc_node_create() overwrites the node and link
capabilities. A request that is then rejected as a duplicate address
has already changed them. Because of the peer ID lookup, this also
happens when the request carries a node address the receiver doesn't
know.
Look up the node by address or peer ID first, as tipc_node_create()
does. For an established node, do the peer net update that
tipc_node_create() did at that point, and call tipc_node_create() only
after the request is known not to be a duplicate. New and preliminary
nodes still go through tipc_node_create() first.
Tested on mainline (7cd8495c0f16) in arm64 QEMU with KASAN, replaying
discovery requests over veth between two network namespaces and logging
the result with a test-only pr_info. Without this patch, in both of two
runs, a duplicate with the peer's node address but a new signature and
media address changed the capabilities from 0xfff to 0x1, and one with
an unknown node address and the peer's ID changed them to 0x21. With
it, both stayed 0xfff in one run. In all three runs, a request with the
peer's signature and media address still updated them, and a request
with a new signature and media address sent while the link was down
was accepted and set them to 0x1. KASAN reported nothing. No selftests
were run.
Fixes: 60020e185704 ("tipc: propagate peer node capabilities to socket layer")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
The issue was found by Claude Opus 5.5 and Claude Fable 5.2 running
Quality Playbook, an LLM-driven code review tool:
https://github.com/andrewstellman/quality-playbook
The fix was drafted with OpenAI GPT-6 (Codex) and this changelog with
Claude Opus 5.5, and both were reviewed by me.
A reproducer is available on request.
net/tipc/node.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/net/tipc/node.c b/net/tipc/node.c
index 53b0993c2c2333..f0e3e06ff8c7bf 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -1176,6 +1176,7 @@ void tipc_node_check_dest(struct net *net, u32 addr,
struct tipc_media_addr *maddr,
bool *respond, bool *dupl_addr)
{
+ struct tipc_net *tn = tipc_net(net);
struct tipc_node *n;
struct tipc_link *l;
struct tipc_link_entry *le;
@@ -1185,6 +1186,7 @@ void tipc_node_check_dest(struct net *net, u32 addr,
bool link_is_reset = false;
bool accept_addr = false;
bool reset = false;
+ bool existing;
char *if_name;
unsigned long intv;
u16 session;
@@ -1192,8 +1194,20 @@ void tipc_node_check_dest(struct net *net, u32 addr,
*dupl_addr = false;
*respond = false;
- n = tipc_node_create(net, addr, peer_id, capabilities, hash_mixes,
- false);
+ spin_lock_bh(&tn->node_list_lock);
+ n = tipc_node_find(net, addr);
+ if (!n)
+ n = tipc_node_find_by_id(net, peer_id);
+ existing = n && !n->preliminary;
+ if (existing && (n->peer_hash_mix ^ hash_mixes))
+ tipc_node_assign_peer_net(n, hash_mixes);
+ spin_unlock_bh(&tn->node_list_lock);
+ if (!existing) {
+ if (n)
+ tipc_node_put(n);
+ n = tipc_node_create(net, addr, peer_id, capabilities,
+ hash_mixes, false);
+ }
if (!n)
return;
@@ -1310,6 +1324,15 @@ void tipc_node_check_dest(struct net *net, u32 addr,
memcpy(&le->maddr, maddr, sizeof(*maddr));
exit:
tipc_node_write_unlock(n);
+ /* Rejected duplicates must not update capabilities. */
+ if (existing && !*dupl_addr) {
+ struct tipc_node *updated;
+
+ updated = tipc_node_create(net, addr, peer_id, capabilities,
+ hash_mixes, false);
+ if (updated)
+ tipc_node_put(updated);
+ }
if (reset && !link_is_reset)
tipc_node_link_down(n, b->identity, false);
tipc_node_put(n);
--
2.53.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* RE: [PATCH net] tipc: don't update capabilities from duplicate discovery requests
2026-11-29 0:17 [PATCH net] tipc: don't update capabilities from duplicate discovery requests Andrew Stellman
@ 2026-11-30 8:20 ` Tung Quang Nguyen
0 siblings, 0 replies; 2+ messages in thread
From: Tung Quang Nguyen @ 2026-11-30 8:20 UTC (permalink / raw)
To: Andrew Stellman
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, netdev, tipc-discussion, linux-kernel, Jon Maloy
>Subject: [PATCH net] tipc: don't update capabilities from duplicate discovery
>requests
>
>From: Andrew Stellman <astellman@stellman-greene.com>
>
>tipc_node_check_dest() calls tipc_node_create() before it classifies a discovery
>request. For an established node, found by node address or by peer ID,
>tipc_node_create() overwrites the node and link capabilities. A request that is
>then rejected as a duplicate address has already changed them. Because of the
>peer ID lookup, this also happens when the request carries a node address the
>receiver doesn't know.
>
>Look up the node by address or peer ID first, as tipc_node_create() does. For
>an established node, do the peer net update that
>tipc_node_create() did at that point, and call tipc_node_create() only after the
>request is known not to be a duplicate. New and preliminary nodes still go
>through tipc_node_create() first.
>
>Tested on mainline (7cd8495c0f16) in arm64 QEMU with KASAN, replaying
>discovery requests over veth between two network namespaces and logging
>the result with a test-only pr_info. Without this patch, in both of two runs, a
>duplicate with the peer's node address but a new signature and media address
>changed the capabilities from 0xfff to 0x1, and one with an unknown node
>address and the peer's ID changed them to 0x21. With it, both stayed 0xfff in
[sashiko]:
The changelog gives the raw capability values (0xfff to 0x1 and 0x21).
What is the user-visible impact of the overwrite?
>one run. In all three runs, a request with the peer's signature and media
>address still updated them, and a request with a new signature and media
>address sent while the link was down was accepted and set them to 0x1.
>KASAN reported nothing. No selftests were run.
>
>Fixes: 60020e185704 ("tipc: propagate peer node capabilities to socket layer")
>Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
>---
>The issue was found by Claude Opus 5.5 and Claude Fable 5.2 running Quality
>Playbook, an LLM-driven code review tool:
>https://github.com/andrewstellman/quality-playbook
>The fix was drafted with OpenAI GPT-6 (Codex) and this changelog with Claude
>Opus 5.5, and both were reviewed by me.
>
>A reproducer is available on request.
>
> net/tipc/node.c | 27 +++++++++++++++++++++++++--
> 1 file changed, 25 insertions(+), 2 deletions(-)
>
>diff --git a/net/tipc/node.c b/net/tipc/node.c index
>53b0993c2c2333..f0e3e06ff8c7bf 100644
>--- a/net/tipc/node.c
>+++ b/net/tipc/node.c
>@@ -1176,6 +1176,7 @@ void tipc_node_check_dest(struct net *net, u32
>addr,
> struct tipc_media_addr *maddr,
> bool *respond, bool *dupl_addr)
> {
>+ struct tipc_net *tn = tipc_net(net);
> struct tipc_node *n;
> struct tipc_link *l;
> struct tipc_link_entry *le;
>@@ -1185,6 +1186,7 @@ void tipc_node_check_dest(struct net *net, u32
>addr,
> bool link_is_reset = false;
> bool accept_addr = false;
> bool reset = false;
>+ bool existing;
> char *if_name;
> unsigned long intv;
> u16 session;
>@@ -1192,8 +1194,20 @@ void tipc_node_check_dest(struct net *net, u32
>addr,
> *dupl_addr = false;
> *respond = false;
>
>- n = tipc_node_create(net, addr, peer_id, capabilities, hash_mixes,
>- false);
>+ spin_lock_bh(&tn->node_list_lock);
>+ n = tipc_node_find(net, addr);
>+ if (!n)
>+ n = tipc_node_find_by_id(net, peer_id);
>+ existing = n && !n->preliminary;
>+ if (existing && (n->peer_hash_mix ^ hash_mixes))
>+ tipc_node_assign_peer_net(n, hash_mixes);
[sashiko]:
Can calling tipc_node_assign_peer_net() here before classifying the request
allow a rejected duplicate discovery message to bind n->peer_net?
If an established remote peer has n->peer_net == NULL and a duplicate node in
a local network namespace uses the same net_id and node_id, a discovery
request from that namespace that is later rejected as *dupl_addr = true will
still set n->peer_net to the local namespace. Because
tipc_node_assign_peer_net() returns early once n->peer_net is set,
tipc_node_xmit() will divert traffic for the remote peer into that local
namespace via tipc_lxc_xmit().
This also mutates n->peer_net and n->peer_hash_mix under tn->node_list_lock
without n->lock, racing with node_lost_contact() and tipc_node_xmit() which
access those fields under n->lock.
>+ spin_unlock_bh(&tn->node_list_lock);
>+ if (!existing) {
>+ if (n)
>+ tipc_node_put(n);
>+ n = tipc_node_create(net, addr, peer_id, capabilities,
>+ hash_mixes, false);
>+ }
[sashiko]:
Does open-coding the node lookup and peer_net assignment here duplicate work
on every discovery packet?
When existing is false, tipc_node_create() immediately re-acquires
tn->node_list_lock and repeats tipc_node_find() and the linear
tipc_node_find_by_id() scan of tn->node_list. When existing is true and the
request is not a duplicate, tipc_node_check_dest() already holds a reference
to n, yet calls tipc_node_create() after tipc_node_write_unlock() even when
n->capabilities == capabilities, repeating the lock acquisition, lookup,
kref get/put, and for_each_net_rcu() scan in tipc_node_assign_peer_net().
> if (!n)
> return;
>
>@@ -1310,6 +1324,15 @@ void tipc_node_check_dest(struct net *net, u32
>addr,
> memcpy(&le->maddr, maddr, sizeof(*maddr));
> exit:
> tipc_node_write_unlock(n);
>+ /* Rejected duplicates must not update capabilities. */
>+ if (existing && !*dupl_addr) {
>+ struct tipc_node *updated;
>+
>+ updated = tipc_node_create(net, addr, peer_id, capabilities,
>+ hash_mixes, false);
>+ if (updated)
>+ tipc_node_put(updated);
>+ }
Can splitting the initial lookup, link setup, and capability update across
separate lock critical sections race with node removal or concurrent
discovery?
CPU0 CPU1
tipc_node_check_dest()
existing = true
tipc_node_write_lock(n)
...
tipc_node_write_unlock(n)
tipc_node_timeout()
tipc_node_cleanup()
list_del_rcu(&n->list)
hlist_del_rcu(&n->hash)
tipc_node_create()
tipc_node_find() -> NULL
kzalloc_obj(*n, ...) <-- inserts blank duplicate node
Because tipc_node_check_dest() does not mark n up or refresh n->delete_at,
tipc_node_cleanup() (or tipc_nl_peer_rm()) can remove a down node from
tn->node_list and tn->node_htable after tipc_node_write_unlock(n), causing
the deferred tipc_node_create() call to allocate and insert a new tipc_node
with INVALID_NODE_SIG and no links.
Separately, when existing is false on entry, dropping tn->node_list_lock and
n before calling tipc_node_create() leaves a window where another CPU can
create or promote the node from preliminary to established and bring a link
up; tipc_node_create() then takes its update path and overwrites capabilities
before duplicate detection runs. And when existing is true,
tipc_link_create() is passed the old n->capabilities under
tipc_node_write_lock(n), exposing the node and new link with stale
n->capabilities and l->peer_caps after tipc_node_write_unlock(n) until
tipc_node_create() re-locks the node.
---
pw-bot: cr
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 8:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 0:17 [PATCH net] tipc: don't update capabilities from duplicate discovery requests Andrew Stellman
2026-11-30 8:20 ` Tung Quang Nguyen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®