Actions
Bug #488
opentt: avoid batadv_send_other_tt_response misses size check
Start date:
10/31/2026
Due date:
% Done:
0%
Estimated time:
Description
This is a pre-existing issue and was not introduced by this patch. The
same 16 bit tvlv_len limit does not seem to be enforced when a node
answers a TT_REQUEST on behalf of another originator.
batadv_send_other_tt_response() only checks this:
/* Don't send the response, if larger than fragmented packet. */
tt_len = sizeof(struct batadv_unicast_tvlv_packet) + tvlv_len;
if (tt_len > READ_ONCE(bat_priv->packet_size_max)) {
That check leaves out the 4 byte batadv_tvlv_hdr. It also has no cap at
sizeof(struct batadv_unicast_tvlv_packet) + U16_MAX.
batadv_tt_prepare_tvlv_global_data() has the same u16-only
check_add_overflow() as the local variant.
A remote originator's global entries come from OGM TT diffs. The local
reserve_lock accounting does not limit them.
Take fragmentation disabled and a hard interface MTU >= 65552. A relayed
table with a 65532 byte TT value (1 VLAN and 5460 entries) passes both
checks. batadv_tvlv_unicast_send() then sends it with tvlv_len truncated
from 65536 to 0.
Only the local reservation and resize paths use the new
batadv_tt_local_transmit_size_max(). Would a check in
batadv_tvlv_unicast_send() that rejects tvlv_value_len >
U16_MAX - sizeof(struct batadv_tvlv_hdr) cover every caller?
Maybe with:
diff --git i/net/batman-adv/translation-table.c w/net/batman-adv/translation-table.c
index 46304069b3b75..5da58a4b87df3 100644
--- i/net/batman-adv/translation-table.c
+++ w/net/batman-adv/translation-table.c
@@ -270,17 +270,16 @@ static int batadv_tt_local_transmit_size(unsigned int num_vlan,
}
/**
- * batadv_tt_local_transmit_size_max() - get the maximum size of a full local table
- * response
+ * batadv_tt_transmit_size_max() - get the maximum size of a TT 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.
+ * A TT 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
+ * Return: maximum size of a TT response in bytes
*/
-static int batadv_tt_local_transmit_size_max(struct batadv_priv *bat_priv)
+static int batadv_tt_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);
@@ -312,7 +311,7 @@ static int batadv_tt_local_transmit_size_max(struct batadv_priv *bat_priv)
static bool batadv_tt_local_reserve(struct batadv_priv *bat_priv, u16 num_vlan,
u16 num_entries, int *table_size)
{
- int size_max = batadv_tt_local_transmit_size_max(bat_priv);
+ int size_max = batadv_tt_transmit_size_max(bat_priv);
unsigned int entries;
unsigned int vlans;
@@ -364,7 +363,7 @@ static bool batadv_tt_local_reserve_entry(struct batadv_priv *bat_priv,
net_ratelimited_function(batadv_info, bat_priv->mesh_iface,
"Local translation table size (%i) exceeds maximum table response size (%i); Ignoring new local tt entry: %pM\n",
table_size,
- batadv_tt_local_transmit_size_max(bat_priv),
+ batadv_tt_transmit_size_max(bat_priv),
addr);
return false;
@@ -400,7 +399,7 @@ bool batadv_tt_local_reserve_vlan(struct batadv_priv *bat_priv,
net_ratelimited_function(batadv_info, bat_priv->mesh_iface,
"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_tt_transmit_size_max(bat_priv),
batadv_print_vid(vid));
return false;
@@ -3781,9 +3780,13 @@ static bool batadv_send_other_tt_response(struct batadv_priv *bat_priv,
req_dst_orig_node);
}
- /* Don't send the response, if larger than fragmented packet. */
- tt_len = sizeof(struct batadv_unicast_tvlv_packet) + tvlv_len;
- if (tt_len > READ_ONCE(bat_priv->packet_size_max)) {
+ /* Don't send the response, if larger than fragmented packet or if
+ * it doesn't fit in the 16 bit tvlv_len of the unicast TVLV packet
+ */
+ tt_len = sizeof(struct batadv_unicast_tvlv_packet);
+ tt_len += sizeof(struct batadv_tvlv_hdr);
+ tt_len += tvlv_len;
+ if (tt_len > batadv_tt_transmit_size_max(bat_priv)) {
net_ratelimited_function(batadv_info, bat_priv->mesh_iface,
"Ignoring TT_REQUEST from %pM; Response size exceeds max packet size.\n",
res_dst_orig_node->orig);
@@ -4755,7 +4758,7 @@ void batadv_tt_local_resize_to_mtu(struct net_device *mesh_iface)
int table_size;
int size_max;
- size_max = batadv_tt_local_transmit_size_max(bat_priv);
+ size_max = batadv_tt_transmit_size_max(bat_priv);
spin_lock_bh(&bat_priv->tt.commit_lock);
diff --git i/net/batman-adv/tvlv.c w/net/batman-adv/tvlv.c
index 93492d393c347..cff69e71e69d9 100644
--- i/net/batman-adv/tvlv.c
+++ w/net/batman-adv/tvlv.c
@@ -737,6 +737,10 @@ void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, const u8 *src,
unsigned int tvlv_len;
struct sk_buff *skb;
+ /* tvlv_len of the unicast TVLV packet must also fit the TVLV header */
+ if (tvlv_value_len > U16_MAX - sizeof(*tvlv_hdr))
+ return;
+
orig_node = batadv_orig_hash_find(bat_priv, dst);
if (!orig_node)
return;
No data to display
Actions