tipc: validate the size of discovery messages before parsing
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 17 lines
Subject: [PATCH] tipc: validate the size of discovery messages before parsing
tipc_disc_rcv()reads the peer net hash, suggested node address and the media address area from header words that live beyond the minimum TIPC header size, and copies a 16 byte node identity from the message data.tipc_msg_validate()only guarantees the minimum header size, so a discovery message (LINK_CONFIGuser) with a smaller declared header or without data makes these accesses read past the end of the message.The path is: a frame received on a TIPC bearer is delivered to
tipc_rcv(), which callstipc_msg_validate()and then dispatches non-sequentialLINK_CONFIGmessages totipc_disc_rcv(). Discovery traffic needs no established link, so any node on the bearer media can send such a message. The accesses can read up to 52 bytes past the end of the validated message but remain inside the skb data allocation, where KASAN does not report them, and the values read are used as the peer's node identity and media address.
Quoted 3 lines
Discovery messages are always built with the maximum size header plus a node identity, see
tipc_disc_init_msg(). Discard discovery messages that do not carry both before accessing the fields.
As mentioned in the changelog, discovery message's header size is stated in tipc_disc_init_msg() and it is a protocol message. So, checking for discarding discovery messages that do not meet the header size is redundant. Note that it is not recommended to create fake discovery messages to exploit TIPC in insecure environment. In such environment, ipsec or encryption must be used
(https://datatracker.ietf.org/doc/html/draft-maloy-tipc-01.txt#section-6).
Quoted 39 lines
Fixes 948fa2d115c5 ("tipc: increase size of tipc discovery messages")Reported-by Abaci <[email protected]>Assisted-by abaci:qwen3.8-maxSigned-off-by Chuyf26 <[email protected]>---
net/tipc/discover.c| 36 ++++++++++++++++++++++++++++--------1 file changed, 28 insertions(+), 8 deletions(-)net/tipc/discover.c index renamed from net/tipc/discover.c +0
-0
685389d4b245..74673ca1f2d5100644net/tipc/discover.c +8
-8@@ -195,27 +195,47 @@ void tipc_disc_rcv(struct net *net, struct sk_buff *skb, {struct tipc_net *tn =tipc_net (net);struct tipc_msg *hdr =buf_msg (skb); -u32 pnet_hash =msg_peer_net_hash (hdr); -u16 caps =msg_node_capabilities (hdr); +u32 pnet_hash; +u16 caps;bool legacy = tn->legacy_addr_format; -u32 sugg =msg_sugg_node_addr (hdr); -u32 signature =msg_node_sig (hdr); +u32 sugg; +u32 signature;u8 peer_id[NODE_ID_LEN ] = {0 ,}; -u32 dst =msg_dest_domain (hdr); -u32 net_id =msg_bc_netid (hdr); +u32 dst; +u32 net_id;struct tipc_media_addr maddr; -u32 src =msg_prevnode (hdr); -u32 mtyp =msg_type (hdr); +u32 src; +u32 mtyp;bool dupl_addr = false;bool respond = false;u32 self;
net/tipc/discover.c void tipc_disc_rcv(struct net *net, struct sk_buff · line 221
Quoted 10 lines
net/tipc/discover.c +8
-0int err; +/* Discovery messages always carry the maximum size TIPC header +* plus a node identity, see tipc_disc_init_msg(). The header +* fields and the media address area accessed below live beyond +* the minimum header size, so discard shorter messages before +* reading them. +*/ +if (msg_hdr_sz (hdr) <MAX_H_SIZE || +msg_size (hdr) <MAX_H_SIZE +NODE_ID_LEN ) {
The second check breaks legacy TIPC (which does not support node identity) as found by sashiko:
" A peer that builds its discovery message the way tipc_disc_init_msg() did before 25b0b9c4e835 ("tipc: handle collisions of 32-bit node address hash values", v4.17) declares exactly that:
net/tipc/msg.c:tipc_msg_init() {
...
msg_set_hdr_sz(m, hsize);
msg_set_size(m, hsize);
...
}"Quoted 22 lines
net/tipc/discover.c +12
-1+kfree_skb (skb); +return ; + } +if (skb_linearize (skb)) {kfree_skb (skb);return ; } hdr =buf_msg (skb); + pnet_hash =msg_peer_net_hash (hdr); + caps =msg_node_capabilities (hdr); + sugg =msg_sugg_node_addr (hdr); + signature =msg_node_sig (hdr); + dst =msg_dest_domain (hdr); + net_id =msg_bc_netid (hdr); + src =msg_prevnode (hdr); + mtyp =msg_type (hdr);if (caps &TIPC_NODE_ID128 )memcpy (peer_id,msg_node_id (hdr),NODE_ID_LEN ); --2.43.5