Skip to content

Commit f2f7358

Browse files
repksimonwunderlich
authored andcommitted
batman-adv: Do not send uninitialized TT changes
The number of TT changes can be less than initially expected in batadv_tt_tvlv_container_update() (changes can be removed by batadv_tt_local_event() in ADD+DEL sequence between reading tt_diff_entries_num and actually iterating the change list under lock). Thus tt_diff_len could be bigger than the actual changes size that need to be sent. Because batadv_send_my_tt_response sends the whole packet, uninitialized data can be interpreted as TT changes on other nodes leading to weird TT global entries on those nodes such as: * 00:00:00:00:00:00 -1 [....] ( 0) 88:12:4e:ad:7e:ba (179) (0x45845380) * 00:00:00:00:78:79 4092 [.W..] ( 0) 88:12:4e:ad:7e:3c (145) (0x8ebadb8b) All of the above also applies to OGM tvlv container buffer's tvlv_len. Remove the extra allocated space to avoid sending uninitialized TT changes in batadv_send_my_tt_response() and batadv_v_ogm_send_softif(). Fixes: e1bf0c1 ("batman-adv: tvlv - convert tt data sent within OGMs") Signed-off-by: Remi Pommarel <[email protected]> Signed-off-by: Sven Eckelmann <[email protected]> Signed-off-by: Simon Wunderlich <[email protected]>
1 parent 40384c8 commit f2f7358

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

net/batman-adv/translation-table.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,7 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)
948948
int tt_diff_len, tt_change_len = 0;
949949
int tt_diff_entries_num = 0;
950950
int tt_diff_entries_count = 0;
951+
size_t tt_extra_len = 0;
951952
u16 tvlv_len;
952953

953954
tt_diff_entries_num = atomic_read(&bat_priv->tt.local_changes);
@@ -985,6 +986,9 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)
985986
}
986987
spin_unlock_bh(&bat_priv->tt.changes_list_lock);
987988

989+
tt_extra_len = batadv_tt_len(tt_diff_entries_num -
990+
tt_diff_entries_count);
991+
988992
/* Keep the buffer for possible tt_request */
989993
spin_lock_bh(&bat_priv->tt.last_changeset_lock);
990994
kfree(bat_priv->tt.last_changeset);
@@ -993,6 +997,7 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)
993997
tt_change_len = batadv_tt_len(tt_diff_entries_count);
994998
/* check whether this new OGM has no changes due to size problems */
995999
if (tt_diff_entries_count > 0) {
1000+
tt_diff_len -= tt_extra_len;
9961001
/* if kmalloc() fails we will reply with the full table
9971002
* instead of providing the diff
9981003
*/
@@ -1005,6 +1010,8 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)
10051010
}
10061011
spin_unlock_bh(&bat_priv->tt.last_changeset_lock);
10071012

1013+
/* Remove extra packet space for OGM */
1014+
tvlv_len -= tt_extra_len;
10081015
container_register:
10091016
batadv_tvlv_container_register(bat_priv, BATADV_TVLV_TT, 1, tt_data,
10101017
tvlv_len);

0 commit comments

Comments
 (0)