From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796386465; b=KUwVvsEHmplpy1RI9ZxMFFA0pwLLexgLJXIgCkYefqTVPIcdhrBTniSAu6k/PHCm23s8 bDMkJjGpAe1DanBEga8o5iquhlKyDhJiXGxnupAVdHC4ejxCbyXcUuPDhlMeUaRJ/pJeo Dp7U2qoofXKaUp6o5aFhU62EWRUijLACgMoL57SFlX6ysXB3hxZajrI54QyGpNB4hOXHG GvNOV3bTfKjFUXZqoE/Pd2qvsosyFCJkNoqJHwg0qU8ZGCluPn3Jmc1p7+J3/LUDrE146 ZBLkG89nkPjFVcoMLfkpaIpY6abABtwCdg0F8NIcXNnepiol8Z8k28mhK9A3TbtyD/A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386465; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=MWrlagKEzri7mpJlLqgYD2fTHmr/k6JsZzBBOvGpC0E=; b=hmWb5hc7ug00tyaOfrTWXQR+F8WwVGC+GQcEfgMWdn15OjQ82N3f9jI0X+NOe5a7jRQ1 IIcozdfPxht+PLV2QlV0nawp/cTKsRTHQ1/SBCIA2p5KZMPddtUeD0yToUKYhhfCGLeFO ZJWEGom/eS5w+FHmqwctRy2mK/Zc6J9YAvDETTXCID2aQDDLX573MuKe/q/6EELrI36dD BjMLPdy0yU+cZEicC0qCkCa4z7ugP2CNRfjL006LsZsJfFxNV/OD1Lpp3rp9Vydb57wdJ 0nfo8YJSxPqzaZl416uc2UHRY6jp1PF6KIIoCpoLjcx8aGiIfUkKtCMVqVl1BUTtMLg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=S082xbVz; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36DA4606A332 for ; Fri, 4 Dec 2026 12:14:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=S082xbVz Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21EE81F00933; Fri, 4 Dec 2026 12:14:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796386465; bh=MWrlagKEzri7mpJlLqgYD2fTHmr/k6JsZzBBOvGpC0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=S082xbVzqz1wJfXSOlxw1W//fJZz+aGik4wR6S16h6f4Kymtm/cGAieIAxACEzm9Q EEj+YovnB421NspNnYvw94i5w9PAi5jbNqciZ9ElYItZPiYaoZxWpd62vOJAZ3FY3F hcS6khfhPdY4qk1RGggmAWy2Nf9lRl5j5dOPSaQDYegXobY6IEldeIMKNEOCbXPtx6 bFQ73RCRR0nSx7aLjaZ5yOVJd5tpBgv0AGspxJQ7jaZ61oMGLe5Fs29W1NNkkMUDzb kfwKz2DdUJKwMhOPMvxiyLY+/8+tTF4xWzzz2m3OsWabQLfymQ9oh0h7XcvbqZAAdc tbHrg5J8ETaIA== From: Sasha Levin To: stable@vger.kernel.org Cc: Kyle Zeng , David Lee , Sven Eckelmann , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6.y 1/2] batman-adv: reject unrepresentable multicast TVLV offsets Date: Fri, 4 Dec 2026 07:14:21 -0500 Message-ID: <20261204121255.2998344-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120228-curdle-uncounted-b8cc@gregkh> References: <2026120228-curdle-uncounted-b8cc@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Kyle Zeng [ Upstream commit f12c2de4f542e3220e17e0606f492110064f04cb ] The network and transport header fields in struct sk_buff are 16-bit offsets from skb->head, and U16_MAX is reserved as the unset transport header value. batadv_tvlv_call_handler() sets both fields from a received multicast TVLV without checking whether the TVLV end is representable. If the end offset exceeds the field's range, skb_set_transport_header() truncates it so that the transport header precedes the network header. The negative difference is then returned by skb_network_header_len() as a large u32. batadv_mcast_forw_packet() consequently accepts an oversized multicast tracker and accesses memory beyond the skb data. Add skb_set_transport_header_careful(), an offset-aware counterpart to skb_reset_transport_header_careful(), which validates the final head-relative offset before assigning it. Use the new helper in batadv_tvlv_call_handler() and reject unrepresentable TVLVs before setting the network header. Fixes: 07afe1ba288c ("batman-adv: mcast: implement multicast packet reception and forwarding") Cc: stable@vger.kernel.org Signed-off-by: Kyle Zeng Co-developed-by: David Lee Signed-off-by: David Lee Acked-by: Sven Eckelmann Link: https://patch.msgid.link/20260817084955.944189-1-david.lee@trailofbits.com Signed-off-by: Jakub Kicinski Stable-dep-of: b9b77e243003 ("net: openvswitch: use skb_set_transport_header_careful() in parse_ipv6hdr()") Signed-off-by: Sasha Levin --- include/linux/skbuff.h | 24 ++++++++++++++++++++++++ net/batman-adv/tvlv.c | 5 ++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 8e61f86133c0c..dc8d0ab5fd1e4 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -2931,6 +2931,30 @@ static inline void skb_set_transport_header(struct sk_buff *skb, skb->transport_header += offset; } +/** + * skb_set_transport_header_careful - conditionally set transport header + * @skb: buffer to alter + * @offset: offset to add to skb->data + * + * Hardened version of skb_set_transport_header(). + * + * Returns: true if the operation was a success. + */ +static inline bool __must_check +skb_set_transport_header_careful(struct sk_buff *skb, const int offset) +{ + long thoff = skb->data - skb->head + offset; + + if (unlikely(thoff != (typeof(skb->transport_header))thoff)) + return false; + + if (unlikely(thoff == (typeof(skb->transport_header))~0U)) + return false; + + skb->transport_header = thoff; + return true; +} + static inline unsigned char *skb_network_header(const struct sk_buff *skb) { return skb->head + skb->network_header; diff --git a/net/batman-adv/tvlv.c b/net/batman-adv/tvlv.c index cc66e231ccb8a..0af30c7653773 100644 --- a/net/batman-adv/tvlv.c +++ b/net/batman-adv/tvlv.c @@ -420,8 +420,11 @@ static int batadv_tvlv_call_handler(struct batadv_priv *bat_priv, return NET_RX_SUCCESS; tvlv_offset = (unsigned char *)tvlv_value - skb->data; + if (!skb_set_transport_header_careful(skb, + tvlv_offset + tvlv_value_len)) + return -EINVAL; + skb_set_network_header(skb, tvlv_offset); - skb_set_transport_header(skb, tvlv_offset + tvlv_value_len); return tvlv_handler->mcast_handler(bat_priv, skb); } -- 2.53.0