From: Tung Quang Nguyen <tung.quang.nguyen@est.tech>
To: Andrew Stellman <bugs@stellman-greene.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"tipc-discussion@lists.sourceforge.net"
<tipc-discussion@lists.sourceforge.net>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Jon Maloy <jmaloy@redhat.com>
Subject: RE: [PATCH net] tipc: don't update capabilities from duplicate discovery requests
Date: Mon, 30 Nov 2026 08:20:14 +0000 [thread overview]
Message-ID: <AM7P189MB113755AA77934424CF54FE01C64E2@AM7P189MB1137.EURP189.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20261129001748.78733-1-bugs@stellman-greene.com>
>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
prev parent reply other threads:[~2026-11-30 8:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 0:17 Andrew Stellman
2026-11-30 8:20 ` Tung Quang Nguyen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AM7P189MB113755AA77934424CF54FE01C64E2@AM7P189MB1137.EURP189.PROD.OUTLOOK.COM \
--to=tung.quang.nguyen@est.tech \
--cc=bugs@stellman-greene.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=jmaloy@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tipc-discussion@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®