[PATCH batadv] batman-adv: mcast: avoid OOB read of num_dests header
Sven Eckelmann <[email protected]> Fri, 03 Jul 2026 20:47:45 +0200
| Newsgroups | org.open-mesh.lists.batman |
|---|---|
| Message-ID | <20260703-mcast-num_tests-access-check-v1-1-278075e2873e@narfation.org> |
Before the access to struct batadv_tvlv_mcast_tracker's num_dests, it is
attempted to check whether enough space is actually in the network header.
But instead of using offsetofend() to check for the whole size (2) which
must be accessible, offsetof() of is called. The latter is always returning
0. The comparison with the network header length will always return that
enough data is available - even when only 1 or 0 bytes are accessible.
Instead of using offsetofend(), use the more common check for the whole
header.
Fixes: 8ed36122d709 ("batman-adv: mcast: implement multicast packet reception and forwarding")
Signed-off-by: Sven Eckelmann <[email protected]>
---
net/batman-adv/multicast_forw.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/net/batman-adv/multicast_forw.c b/net/batman-adv/multicast_forw.c
index f2e53c7c..60ad3a55 100644
--- a/net/batman-adv/multicast_forw.c
+++ b/net/batman-adv/multicast_forw.c
@@ -926,7 +926,6 @@ static int batadv_mcast_forw_packet(struct batadv_priv *bat_priv,
{
struct batadv_tvlv_mcast_tracker *mcast_tracker;
struct batadv_neigh_node *neigh_node;
- unsigned long num_dests_off;
struct sk_buff *nexthop_skb;
unsigned char *skb_net_hdr;
bool local_recv = false;
@@ -941,9 +940,8 @@ static int batadv_mcast_forw_packet(struct batadv_priv *bat_priv,
/* (at least) TVLV part needs to be linearized */
SKB_LINEAR_ASSERT(skb);
- /* check if num_dests is within skb length */
- num_dests_off = offsetof(struct batadv_tvlv_mcast_tracker, num_dests);
- if (num_dests_off > skb_network_header_len(skb))
+ /* check if batadv_tvlv_mcast_tracker header is within skb length */
+ if (sizeof(*mcast_tracker) > skb_network_header_len(skb))
return -EINVAL;
skb_net_hdr = skb_network_header(skb);
---
base-commit: 22b12d005035f37f898e5bf80480719fe1ef4fba
change-id: 20260703-mcast-num_tests-access-check-e2d7ef8e607e
Best regards,
--
Sven Eckelmann <[email protected]>