From: Sven Eckelmann batadv_send_other_tt_response() answers a TT request on behalf of another originator. It only checks the unicast TVLV header and the TT TVLV against packet_size_max. The check has two problems: * The TVLV header (struct batadv_tvlv_hdr) is not counted. The response can be 4 bytes larger than packet_size_max. * The tvlv_len of the unicast TVLV packet covers the TVLV header and the TT TVLV. It is only 16 bit wide. A larger packet_size_max allows a response which doesn't fit. batadv_tvlv_unicast_send() then sends it with a truncated tvlv_len. The size of the global table of another originator is not limited by the reservation of the local table. The response must therefore be checked before it is sent. Count the TVLV header and use the limit which is already used for the local table. The helper is no longer specific to the local table and is renamed to batadv_tt_transmit_size_max(). Reported-by: Sashiko Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261030135105.2555887-1-sw%40simonwunderlich.de?part=14 Signed-off-by: Sven Eckelmann Signed-off-by: Simon Wunderlich --- net/batman-adv/translation-table.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index e69f8876ef7d..b6749fed3a16 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -272,17 +272,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. + * The 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); @@ -314,7 +313,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; @@ -366,7 +365,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; @@ -402,7 +401,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; @@ -4053,8 +4052,10 @@ static bool batadv_send_other_tt_response(struct batadv_priv *bat_priv, } /* 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)) { + 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); @@ -5132,7 +5133,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); -- 2.47.3