[PATCH] batman-adv: reject unrepresentable multicast TVLV offsets
From: David Lee
Date: Fri Jul 31 2026 - 10:05:56 EST
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 without checking
that the end of a received multicast TVLV is representable.
A sufficiently large TVLV therefore wraps the transport header offset.
skb_network_header_len() then returns a bogus large length, allowing
batadv_mcast_forw_packet() to access memory beyond the skb data.
Reject multicast TVLVs whose absolute end offset cannot be represented
before changing either header field.
Fixes: 07afe1ba288c ("batman-adv: mcast: implement multicast packet reception and forwarding")
Bug found and triaged by OpenAI Security Research and
validated by Trail of Bits.
Assisted-by: Codex:gpt-5.6-sol gpt-5.5-cyber
Signed-off-by: Kyle Zeng <kylebot@xxxxxxxxxx>
---
Trail of Bits has a reproducer for this bug that triggers a
KASAN use-after-free and can share if needed.
net/batman-adv/tvlv.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/batman-adv/tvlv.c b/net/batman-adv/tvlv.c
index 1c9fb2198..5e9d0e2dd 100644
--- a/net/batman-adv/tvlv.c
+++ b/net/batman-adv/tvlv.c
@@ -433,6 +433,9 @@ 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_headroom(skb) + tvlv_offset + tvlv_value_len >= U16_MAX)
+ return -EINVAL;
+
skb_set_network_header(skb, tvlv_offset);
skb_set_transport_header(skb, tvlv_offset + tvlv_value_len);
--
2.53.0