From: Simon Wunderlich <sw@simonwunderlich.de>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
b.a.t.m.a.n@lists.open-mesh.org,
Sven Eckelmann <sven@narfation.org>,
Sashiko <sashiko-bot@kernel.org>,
stable+noautosel@kernel.org,
Simon Wunderlich <sw@simonwunderlich.de>
Subject: [PATCH net v2 14/14] batman-adv: tt: limit local table to single TVLV response size
Date: Fri, 30 Oct 2026 14:51:05 +0100 [thread overview]
Message-ID: <20261030135105.2555887-15-sw@simonwunderlich.de> (raw)
In-Reply-To: <20261030135105.2555887-1-sw@simonwunderlich.de>
From: Sven Eckelmann <sven@narfation.org>
The reservation of local TT entries and VLANs only limits the local table
by (int) packet_size_max. But the full table response is sent as a single
unicast TVLV packet whose tvlv_len (covering the TVLV header and the TT
TVLV) is only 16 bit wide. The reservation must therefore be capped at the
minimum of both the packet_size_max and the maximum theoretic table
response.
The size limit was already missing the 16 bit tvlv_len cap since the
original packet_size_max check was introduced. But this check was only
reachable with fragmentation disabled and a hard interface MTU larger than
the maximum unicast TVLV packet. In this case,
batadv_tt_prepare_tvlv_local_data() refuses to build the full table
response and no oversized packet is created. It is therefore mostly
affecting the commit 85fb027f611b ("batman-adv: tt: reject VLAN/TT entries
before reaching size limit"), which should prevent this kind of
overallocation.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260930094558.3723766-2-sw%40simonwunderlich.de?part=8
Fixes: a19d3d85e1b8 ("batman-adv: limit local translation table max size")
Cc: <stable+noautosel@kernel.org> # requires 85fb027f611b, old behavior only affects MTU > 64KiB without fragmentation
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
net/batman-adv/translation-table.c | 69 ++++++++++++++++++++----------
1 file changed, 47 insertions(+), 22 deletions(-)
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index f0100ccf93deb..46304069b3b75 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -26,8 +26,10 @@
#include <linux/jhash.h>
#include <linux/jiffies.h>
#include <linux/kref.h>
+#include <linux/limits.h>
#include <linux/list.h>
#include <linux/lockdep.h>
+#include <linux/minmax.h>
#include <linux/net.h>
#include <linux/netdevice.h>
#include <linux/netlink.h>
@@ -253,7 +255,8 @@ static int batadv_tt_len(int changes_num)
*
* Return: local translation table size in bytes.
*/
-static int batadv_tt_local_transmit_size(u16 num_vlan, u16 num_entries)
+static int batadv_tt_local_transmit_size(unsigned int num_vlan,
+ unsigned int num_entries)
{
int hdr_size;
@@ -266,6 +269,25 @@ static int batadv_tt_local_transmit_size(u16 num_vlan, u16 num_entries)
return hdr_size + batadv_tt_len(num_entries);
}
+/**
+ * batadv_tt_local_transmit_size_max() - get the maximum size of a full local table
+ * response
+ * @bat_priv: the bat priv with all the mesh interface information
+ *
+ * The full table response is sent as a single unicast TVLV packet. Its
+ * tvlv_len, which covers the TVLV header and the TT TVLV, is only 16 bit wide.
+ * This limits the response size even when packet_size_max is larger.
+ *
+ * Return: maximum size of a full local table response in bytes
+ */
+static int batadv_tt_local_transmit_size_max(struct batadv_priv *bat_priv)
+{
+ int tvlv_size_max = sizeof(struct batadv_unicast_tvlv_packet) + U16_MAX;
+ int packet_size_max = READ_ONCE(bat_priv->packet_size_max);
+
+ return min(packet_size_max, tvlv_size_max);
+}
+
/**
* batadv_tt_local_reserve() - reserve room in the transmittable local table
* @bat_priv: the bat priv with all the mesh interface information
@@ -290,22 +312,23 @@ static int batadv_tt_local_transmit_size(u16 num_vlan, u16 num_entries)
static bool batadv_tt_local_reserve(struct batadv_priv *bat_priv, u16 num_vlan,
u16 num_entries, int *table_size)
{
- int packet_size_max = READ_ONCE(bat_priv->packet_size_max);
+ int size_max = batadv_tt_local_transmit_size_max(bat_priv);
+ unsigned int entries;
+ unsigned int vlans;
scoped_guard(spinlock_bh, &bat_priv->tt.reserve_lock) {
- bat_priv->tt.reserved_vlans += num_vlan;
- bat_priv->tt.reserved_entries += num_entries;
+ vlans = bat_priv->tt.reserved_vlans + num_vlan;
+ entries = bat_priv->tt.reserved_entries + num_entries;
- *table_size = batadv_tt_local_transmit_size(bat_priv->tt.reserved_vlans,
- bat_priv->tt.reserved_entries);
- if (*table_size <= packet_size_max)
- return true;
+ *table_size = batadv_tt_local_transmit_size(vlans, entries);
+ if (*table_size > size_max)
+ return false;
- bat_priv->tt.reserved_vlans -= num_vlan;
- bat_priv->tt.reserved_entries -= num_entries;
+ bat_priv->tt.reserved_vlans = vlans;
+ bat_priv->tt.reserved_entries = entries;
}
- return false;
+ return true;
}
/**
@@ -339,9 +362,10 @@ static bool batadv_tt_local_reserve_entry(struct batadv_priv *bat_priv,
return true;
net_ratelimited_function(batadv_info, bat_priv->mesh_iface,
- "Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new local tt entry: %pM\n",
+ "Local translation table size (%i) exceeds maximum table response size (%i); Ignoring new local tt entry: %pM\n",
table_size,
- READ_ONCE(bat_priv->packet_size_max), addr);
+ batadv_tt_local_transmit_size_max(bat_priv),
+ addr);
return false;
}
@@ -374,8 +398,9 @@ bool batadv_tt_local_reserve_vlan(struct batadv_priv *bat_priv,
return true;
net_ratelimited_function(batadv_info, bat_priv->mesh_iface,
- "Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new VLAN: %d\n",
- table_size, READ_ONCE(bat_priv->packet_size_max),
+ "Local translation table size (%i) exceeds maximum table response size (%i); Ignoring new VLAN: %d\n",
+ table_size,
+ batadv_tt_local_transmit_size_max(bat_priv),
batadv_print_vid(vid));
return false;
@@ -724,9 +749,9 @@ static u16 batadv_tt_entries(u16 tt_len)
*/
static int batadv_tt_local_table_transmit_size(struct batadv_priv *bat_priv)
{
+ unsigned int tt_local_entries = 0;
struct batadv_meshif_vlan *vlan;
- u16 tt_local_entries = 0;
- u16 num_vlan = 0;
+ unsigned int num_vlan = 0;
rcu_read_lock();
hlist_for_each_entry_rcu(vlan, &bat_priv->meshif_vlan_list, list) {
@@ -4727,16 +4752,16 @@ void batadv_tt_local_resize_to_mtu(struct net_device *mesh_iface)
struct batadv_priv *bat_priv = netdev_priv(mesh_iface);
int timeout = BATADV_TT_LOCAL_TIMEOUT / 2;
bool reduced = false;
- int packet_size_max;
int table_size;
+ int size_max;
- packet_size_max = READ_ONCE(bat_priv->packet_size_max);
+ size_max = batadv_tt_local_transmit_size_max(bat_priv);
spin_lock_bh(&bat_priv->tt.commit_lock);
while (timeout) {
table_size = batadv_tt_local_table_transmit_size(bat_priv);
- if (packet_size_max >= table_size)
+ if (size_max >= table_size)
break;
batadv_tt_local_purge(bat_priv, timeout);
@@ -4745,8 +4770,8 @@ void batadv_tt_local_resize_to_mtu(struct net_device *mesh_iface)
timeout /= 2;
reduced = true;
net_ratelimited_function(batadv_info, mesh_iface,
- "Forced to purge local tt entries to fit new maximum fragment MTU (%i)\n",
- packet_size_max);
+ "Forced to purge local tt entries to fit new maximum table response size (%i)\n",
+ size_max);
}
/* commit these changes immediately, to avoid synchronization problem
--
2.47.3
prev parent reply other threads:[~2026-10-30 13:51 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 13:50 [PATCH net 00/14] pull request: batman-adv 2026-10-30 Simon Wunderlich
2026-10-30 13:50 ` [PATCH net 01/14] batman-adv: avoid WARN_ON for orig_ifinfo allocation failure Simon Wunderlich
2026-10-30 13:54 ` netdev-bot+sinfo
2026-10-30 13:50 ` [PATCH net v2 02/14] batman-adv: Close OGM aggregation before transmission Simon Wunderlich
2026-10-30 13:50 ` [PATCH net 03/14] batman-adv: mcast: validate tracker padding before forwarding Simon Wunderlich
2026-10-30 13:50 ` [PATCH net 04/14] batman-adv: tpmeter: fix u32 truncation of reported bytes Simon Wunderlich
2026-10-30 13:50 ` [PATCH net 05/14] batman-adv: dat: initialize orig_node of unfilled candidate slots Simon Wunderlich
2026-10-30 13:50 ` [PATCH net 06/14] batman-adv: fix skb leak when hard_iface is being released Simon Wunderlich
2026-10-30 13:50 ` [PATCH net 07/14] batman-adv: stop originator purge worker before freeing TT Simon Wunderlich
2026-10-30 13:50 ` [PATCH net v2 08/14] batman-adv: tt: only transmit local ROAM flag together with DEL Simon Wunderlich
2026-10-30 13:51 ` [PATCH net 09/14] batman-adv: tt: clear ROAM flag when re-adding a pending local client Simon Wunderlich
2026-10-30 13:51 ` [PATCH net 10/14] batman-adv: tt: send ROAM_ADV on each roamed back client Simon Wunderlich
2026-10-30 13:51 ` [PATCH net 11/14] batman-adv: tt: ignore ROAM flag of received ADD changes Simon Wunderlich
2026-10-30 13:51 ` [PATCH net v2 12/14] batman-adv: tt: only update flags for TT events Simon Wunderlich
2026-10-30 13:51 ` [PATCH net v2 13/14] batman-adv: tt: don't drop local events queued during TVLV update Simon Wunderlich
2026-10-30 13:51 ` Simon Wunderlich [this message]
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=20261030135105.2555887-15-sw@simonwunderlich.de \
--to=sw@simonwunderlich.de \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sashiko-bot@kernel.org \
--cc=stable+noautosel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox