[PATCH net v2] tipc: validate peer address attributes in tipc_nl_peer_rm()
From: Ian Rogers
Date: Thu Dec 03 2026 - 11:59:42 EST
tipc_nl_peer_rm() documents TIPC_NLA_NET_ADDR and TIPC_NLA_NET_NODEID as
mutually exclusive ways to identify the peer to remove, but checks them
in two independent if-blocks with no fallback. If a TIPC_NL_PEER_REMOVE
netlink request contains an empty nested TIPC_NLA_NET attribute (or only
unrelated TIPC_NLA_NET_* attributes), 'addr' stays uninitialized on the
stack and is passed to in_own_node() and tipc_node_find(). If both
attributes are present, TIPC_NLA_NET_NODEID silently overwrites the
address parsed from TIPC_NLA_NET_ADDR.
Return -EINVAL when both attributes are supplied or when neither is
present.
Found with Clang's -Wconditional-uninitialized on an x86_64 allyesconfig
build; Gemini helped review the code path, draft the patch and commit
message, and write the QEMU netlink test script. Without this patch on
an unmodified kernel booted in QEMU (built with
CONFIG_INIT_STACK_NONE=y, no kernel modifications or error injection),
sending a TIPCv2 generic netlink TIPC_NL_PEER_REMOVE message with an
empty nested TIPC_NLA_NET, with only TIPC_NLA_NET_ID, or with both
TIPC_NLA_NET_ADDR and TIPC_NLA_NET_NODEID all fell through to
tipc_node_find() and returned -ENXIO instead of -EINVAL.
Build-tested with LLVM=1 W=1 (-Werror) and -Wconditional-uninitialized.
Runtime-tested in QEMU with CONFIG_INIT_STACK_NONE=y,
CONFIG_KCSAN_STRICT=y, and CONFIG_PROVE_LOCKING=y: all three malformed
requests (plus zero TIPC_NLA_NET_ADDR and TIPC_NLA_NET_NODEID without
TIPC_NLA_NET_NODEID_W1) return -EINVAL, unknown valid addresses/node IDs
return -ENXIO, and live peer discovery plus offline peer removal
('tipc peer remove address 1.1.2') over a veth pair between two network
namespaces succeeds with no KCSAN or lockdep reports. No TIPC selftest
exists under tools/testing/selftests/net/.
Fixes: 43fcd906d9c1 ("tipc: support 128bit node identity for peer removing")
Reviewed-by: Tung Nguyen <tung.quang.nguyen@xxxxxxxx>
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
Notes:
v2:
- Reproduced the unpatched behavior and runtime-tested the fix in QEMU
over TIPCv2 generic netlink and live veth/netns peer removal
(Paolo Abeni).
- Carried Reviewed-by from Tung Nguyen (code unchanged from v1).
v1: https://lore.kernel.org/r/20261119170556.1518068-1-irogers@xxxxxxxxxx
net/tipc/node.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/net/tipc/node.c b/net/tipc/node.c
index 53b0993c2c23..d19ed94b8f41 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -2277,18 +2277,21 @@ int tipc_nl_peer_rm(struct sk_buff *skb, struct genl_info *info)
/* attrs[TIPC_NLA_NET_NODEID] and attrs[TIPC_NLA_NET_ADDR] are
* mutually exclusive cases
*/
+ if (attrs[TIPC_NLA_NET_ADDR] && attrs[TIPC_NLA_NET_NODEID])
+ return -EINVAL;
+
if (attrs[TIPC_NLA_NET_ADDR]) {
addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]);
if (!addr)
return -EINVAL;
- }
-
- if (attrs[TIPC_NLA_NET_NODEID]) {
+ } else if (attrs[TIPC_NLA_NET_NODEID]) {
if (!attrs[TIPC_NLA_NET_NODEID_W1])
return -EINVAL;
*w0 = nla_get_u64(attrs[TIPC_NLA_NET_NODEID]);
*w1 = nla_get_u64(attrs[TIPC_NLA_NET_NODEID_W1]);
addr = hash128to32(node_id);
+ } else {
+ return -EINVAL;
}
if (in_own_node(net, addr))
--
2.56.1.911.g883d8bcb20-goog