Skip to content

Commit f4c9c2c

Browse files
repksimonwunderlich
authored andcommitted
batman-adv: Fix incorrect offset in batadv_tt_tvlv_ogm_handler_v1()
Since commit 4436df4 ("batman-adv: Add flex array to struct batadv_tvlv_tt_data"), the introduction of batadv_tvlv_tt_data's flex array member in batadv_tt_tvlv_ogm_handler_v1() put tt_changes at invalid offset. Those TT changes are supposed to be filled from the end of batadv_tvlv_tt_data structure (including vlan_data flexible array), but only the flex array size is taken into account missing completely the size of the fixed part of the structure itself. Fix the tt_change offset computation by using struct_size() instead of flex_array_size() so both flex array member and its container structure sizes are taken into account. Cc: stable@vger.kernel.org Fixes: 4436df4 ("batman-adv: Add flex array to struct batadv_tvlv_tt_data") Signed-off-by: Remi Pommarel <repk@triplefau.lt> Signed-off-by: Sven Eckelmann <sven@narfation.org> Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
1 parent 8c8ecc9 commit f4c9c2c

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

net/batman-adv/translation-table.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3959,23 +3959,21 @@ static void batadv_tt_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
39593959
struct batadv_tvlv_tt_change *tt_change;
39603960
struct batadv_tvlv_tt_data *tt_data;
39613961
u16 num_entries, num_vlan;
3962-
size_t flex_size;
3962+
size_t tt_data_sz;
39633963

39643964
if (tvlv_value_len < sizeof(*tt_data))
39653965
return;
39663966

39673967
tt_data = tvlv_value;
3968-
tvlv_value_len -= sizeof(*tt_data);
3969-
39703968
num_vlan = ntohs(tt_data->num_vlan);
39713969

3972-
flex_size = flex_array_size(tt_data, vlan_data, num_vlan);
3973-
if (tvlv_value_len < flex_size)
3970+
tt_data_sz = struct_size(tt_data, vlan_data, num_vlan);
3971+
if (tvlv_value_len < tt_data_sz)
39743972
return;
39753973

39763974
tt_change = (struct batadv_tvlv_tt_change *)((void *)tt_data
3977-
+ flex_size);
3978-
tvlv_value_len -= flex_size;
3975+
+ tt_data_sz);
3976+
tvlv_value_len -= tt_data_sz;
39793977

39803978
num_entries = batadv_tt_entries(tvlv_value_len);
39813979

0 commit comments

Comments
 (0)