tipc: drop discovery messages shorter than the fields they carry
Subsystems (3)
PATCH 1/1 tipc: drop discovery messages shorter than the fields they carry
tipc_disc_rcv() reads the media address and words 13 and 14 of a full MAX_H_SIZE header, and the 128-bit node identity from the data after it, but tipc_msg_validate() only checks that the declared header is at least MIN_H_SIZE. A peer on the bearer can send a discovery message with a 24-byte header, and those fields are then read from past the end of the message. For a UDP bearer, tipc_udp_msg2addr() takes the peer's address from there:
BUG: KMSAN: uninit-value in tipc_udp_msg2addr (net/tipc/udp_media.c:129) tipc_udp_msg2addr (net/tipc/udp_media.c:129 net/tipc/udp_media.c:159) tipc_disc_rcv (net/tipc/discover.c:227) tipc_rcv (net/tipc/node.c:2136) tipc_udp_recv (net/tipc/udp_media.c:389) udp_queue_rcv_one_skb (net/ipv4/udp.c:2433) udp_queue_rcv_skb (net/ipv4/udp.c:2473) Uninit was created at: kmem_cache_alloc_node_noprof (mm/slub.c:5105) __alloc_skb (net/core/skbuff.c:616 net/core/skbuff.c:716)
Discovery messages have been sent with a MAX_H_SIZE header since commit 948fa2d115c5 ("tipc: increase size of tipc discovery messages"), and with the node identity after it when TIPC_NODE_ID128 is set. Drop the shorter ones.
---
The issue was found by an LLM-guided test generator that we are developing as a research prototype: as an unprivileged user in its own user and network namespace, it enables a UDP bearer and sends it a discovery message with a 24-byte header. KASAN stays quiet, as the bytes read are in the skb's tailroom; KMSAN reports them as above, and the kernel logs "Rcv corrupt discovery message" for the address built from them.
The patch was written with LLM assistance; we reviewed and tested it. With it, the short message is dropped without KMSAN reports, and two namespaces joined by a veth pair with UDP bearers still discover each other and bring the link up.
net/tipc/discover.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/tipc/discover.c +6 -0
@@ -219,6 +219,12 @@ void tipc_disc_rcv(struct net *net, struct sk_buff *skb, } hdr =buf_msg (skb); +if (msg_hdr_sz (hdr) <MAX_H_SIZE || + ((caps &TIPC_NODE_ID128 ) &&msg_data_sz (hdr) <NODE_ID_LEN )) { +kfree_skb (skb); +return ; + } +if (caps &TIPC_NODE_ID128 )memcpy (peer_id,msg_node_id (hdr),NODE_ID_LEN );else
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The new check in tipc_disc_rcv() (msg_hdr_sz(hdr) < MAX_H_SIZE) silently drops every LINK_CONFIG message with a header…
- [Low] In net/tipc/discover.c, tipc_disc_rcv() still reads words 13 and 14 of the header before the new length check runs.
--
tipc: drop discovery messages shorter than the fields they carry
This adds a length check to tipc_disc_rcv() in net/tipc/discover.c. It drops LINK_CONFIG messages whose declared header is shorter than MAX_H_SIZE, and also those whose data is shorter than NODE_ID_LEN when TIPC_NODE_ID128 is set. The aim is to stop the media address, words 13 and 14, and the node identity being read from beyond the end of the message.
net/tipc/discover.c void tipc_disc_rcv(struct net *net, struct sk_buff *skb, · line 226
Quoted 13 lines
net/tipc/discover.c +5
-0@@ -219,6 +219,12 @@ void tipc_disc_rcv(struct net *net, struct sk_buff *skb, } hdr =buf_msg (skb); +if (msg_hdr_sz (hdr) <MAX_H_SIZE || + ((caps &TIPC_NODE_ID128 ) &&msg_data_sz (hdr) <NODE_ID_LEN )) { +kfree_skb (skb); +return ; + }
[Severity: Medium]
Will this also drop discovery messages from older peers that send a 40-byte INT_H_SIZE header?
Before commit 948fa2d115c5 ("tipc: increase size of tipc discovery messages"), tipc_disc_init_msg() built discovery messages with an INT_H_SIZE header. That commit's message says 40 bytes "was enough for Ethernet/IB/IPv4".
tipc_msg_validate() accepts any hsz from MIN_H_SIZE to MAX_H_SIZE, so these messages still reach tipc_disc_rcv() via tipc_rcv():
if (unlikely(usr == LINK_CONFIG))
return tipc_disc_rcv(net, skb, b);The Ethernet and InfiniBand decoders only read bytes inside a 40-byte header:
- tipc_eth_msg2addr() reads header bytes 24 to 29.
- tipc_ib_msg2addr() reads 20 bytes starting at byte 20, so it stops
at byte 40.
The receiver also still handles peers without TIPC_NODE_ID128:
else
sprintf(peer_id, "%x", src);Before this patch, discovery with these peers over Ethernet or IB could still complete, although words 13 and 14 held garbage. After it, the messages are freed without the "Rcv corrupt discovery message" warning, and neighbour discovery with those peers stops.
Is dropping interop with these peers intended? If so, could the commit message say so? The Fixes: tag points at the initial merge, so this change would go to every stable tree.
Or could the minimum length depend on what each media and the words 13/14 consumers actually need, so that 40-byte Ethernet/IB discovery keeps working?
[Severity: Low]
This isn't a bug, but words 13 and 14 are still read before this new check runs. At the top of tipc_disc_rcv():
struct tipc_msg *hdr = buf_msg(skb);
u32 pnet_hash = msg_peer_net_hash(hdr);
u16 caps = msg_node_capabilities(hdr);
bool legacy = tn->legacy_addr_format;
u32 sugg = msg_sugg_node_addr(hdr);msg_peer_net_hash() returns msg_word(m, 13), and msg_sugg_node_addr() returns msg_word(m, 14). Both run before skb_linearize() and before the msg_hdr_sz(hdr) < MAX_H_SIZE test. With a 24-byte header, both words are still loaded from past the validated header.
The short message is dropped before pnet_hash reaches tipc_node_check_dest() or sugg reaches tipc_disc_addr_trial_msg(), so those values are never used.
Could these two reads, or the check, be reordered so the check comes first? That would match the commit message, which says these fields "are then read from past the end of the message".
Quoted 4 lines
net/tipc/discover.c +0
-0if (caps &TIPC_NODE_ID128 )memcpy (peer_id,msg_node_id (hdr),NODE_ID_LEN );else
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179550610427.774194.2378040347436778640%40gmail.com
Tung Quang Nguyen
maintainerQuoted 9 lines
Subject: [PATCH net] tipc: drop discovery messages shorter than the fields they carry
tipc_disc_rcv()reads the media address and words 13 and 14 of a fullMAX_H_SIZEheader, and the 128-bit node identity from the data after it, buttipc_msg_validate()only checks that the declared header is at leastMIN_H_SIZE. A peer on the bearer can send a discovery message with a 24- byte header, and those fields are then read from past the end of the message. For a UDP bearer,tipc_udp_msg2addr()takes the peer's address from there:
Discovery message's header size (MAX_H_SIZE == 60) is stated in tipc_disc_init_msg() and it is a protocol message. How can the peer send a discovery message with a 24-byte header ?
Quoted 39 lines
BUG: KMSAN: uninit-value in tipc_udp_msg2addr (net/tipc/udp_media.c:129) tipc_udp_msg2addr (net/tipc/udp_media.c:129 net/tipc/udp_media.c:159) tipc_disc_rcv (net/tipc/discover.c:227) tipc_rcv (net/tipc/node.c:2136) tipc_udp_recv (net/tipc/udp_media.c:389) udp_queue_rcv_one_skb (net/ipv4/udp.c:2433) udp_queue_rcv_skb (net/ipv4/udp.c:2473) Uninit was created at: kmem_cache_alloc_node_noprof (mm/slub.c:5105) __alloc_skb (net/core/skbuff.c:616 net/core/skbuff.c:716)Discovery messages have been sent with a
MAX_H_SIZEheader since commit948fa2d115c5("tipc: increase size of tipc discovery messages"), and with the node identity after it whenTIPC_NODE_ID128is set. Drop the shorter ones.Fixes b97bf3fd8f6a ("[TIPC] Initial merge")Signed-off-by Kyuwon Cho <[email protected]>---
The issue was found by an LLM-guided test generator that we are developing as a research prototype: as an unprivileged user in its own user and network namespace, it enables a UDP bearer and sends it a discovery message with a 24-byte header. KASAN stays quiet, as the bytes read are in the skb's tailroom; KMSAN reports them as above, and the kernel logs "Rcv corrupt discovery message" for the address built from them.The patch was written with LLM assistance; we reviewed and tested it. With it, the short message is dropped without KMSAN reports, and two namespaces joined by a veth pair with UDP bearers still discover each other and bring the link up.
net/tipc/discover.c| 6 ++++++1 file changed, 6 insertions(+)net/tipc/discover.c index renamed from net/tipc/discover.c +0
-0
b9d06595b067..0f99e4af1cfa100644
net/tipc/discover.c void tipc_disc_rcv(struct net *net, struct sk_buff *skb, · line 222
Quoted 4 lines
net/tipc/discover.c +1
-0@@ -219,6 +219,12 @@ void tipc_disc_rcv(struct net *net, struct sk_buff *skb, } hdr =buf_msg (skb); + if (msg_hdr_sz(hdr) < MAX_H_SIZE ||
As sashiko pointed out, the lecacy node (before commit 948fa2d115c5 ("tipc: increase size of tipc discovery messages") sends 40-byte header. The above check will drop that discovery message. This breaks our compatibility rule.
---
pw-bot: cr
Hi Tung,
Quoted 2 lines · Tung Quang Nguyen
Discovery message's header size (
MAX_H_SIZE== 60) is stated intipc_disc_init_msg()and it is a protocol message. How can the peer send a discovery message with a 24-byte header ?
A TIPC node cannot. Anyone who can reach the bearer can, though: the message in our test is built by hand and sent as a plain UDP datagram to the bearer's port, with no TIPC node involved.
Quoted 2 lines
As sashiko pointed out, the lecacy node (before commit
948fa2d115c5("tipc: increase size of tipc discovery messages") sends 40-byte header. The above check will drop that discovery message. This breaks our compatibility rule.
Since forged discovery messages are outside TIPC's model, I'll drop this patch.
Thanks,
Kyuwon