From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Kyle Zeng <kylebot@openai.com>,
David Lee <david.lee@trailofbits.com>,
Sven Eckelmann <sven@narfation.org>,
Jakub Kicinski <kuba@kernel.org>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.6.y 1/2] batman-adv: reject unrepresentable multicast TVLV offsets
Date: Fri, 4 Dec 2026 07:14:14 -0500 [thread overview]
Message-ID: <20261204121248.2994078-1-sashal@kernel.org> (raw)
In-Reply-To: <2026120222-lilly-relight-c1c4@gregkh>
From: Kyle Zeng <kylebot@openai.com>
[ 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 <kylebot@openai.com>
Co-developed-by: David Lee <david.lee@trailofbits.com>
Signed-off-by: David Lee <david.lee@trailofbits.com>
Acked-by: Sven Eckelmann <sven@narfation.org>
Link: https://patch.msgid.link/20260817084955.944189-1-david.lee@trailofbits.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Stable-dep-of: 425b1fe50b71 ("ipv6: mcast: use skb_set_transport_header_careful() in ipv6_mc_check_exthdrs()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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
next prev parent reply other threads:[~2026-12-04 12:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 15:10 FAILED: patch "[PATCH] ipv6: mcast: use skb_set_transport_header_careful() in" failed to apply to 6.6-stable tree gregkh
2026-12-04 12:14 ` Sasha Levin [this message]
2026-12-04 12:14 ` [PATCH 6.6.y 2/2] ipv6: mcast: use skb_set_transport_header_careful() in ipv6_mc_check_exthdrs() Sasha Levin
-- strict thread matches above, loose matches on Subject: below --
2026-12-02 15:11 FAILED: patch "[PATCH] net: openvswitch: use skb_set_transport_header_careful() in" failed to apply to 6.6-stable tree gregkh
2026-12-04 12:14 ` [PATCH 6.6.y 1/2] batman-adv: reject unrepresentable multicast TVLV offsets Sasha Levin
2026-12-02 15:08 FAILED: patch "[PATCH] sctp: use skb_set_transport_header_careful() in sctp_v6_err()" failed to apply to 6.6-stable tree gregkh
2026-12-04 12:12 ` [PATCH 6.6.y 1/2] batman-adv: reject unrepresentable multicast TVLV offsets Sasha Levin
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=20261204121248.2994078-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=david.lee@trailofbits.com \
--cc=kuba@kernel.org \
--cc=kylebot@openai.com \
--cc=stable@vger.kernel.org \
--cc=sven@narfation.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.