Skip to content

Commit 8038806

Browse files
repksimonwunderlich
authored andcommitted
batman-adv: Remove uninitialized data in full table TT response
The number of entries filled by batadv_tt_tvlv_generate() can be less than initially expected in batadv_tt_prepare_tvlv_{global,local}_data() (changes can be removed by batadv_tt_local_event() in ADD+DEL sequence in the meantime as the lock held during the whole tvlv global/local data generation). Thus tvlv_len could be bigger than the actual TT entry size that need to be sent so full table TT_RESPONSE could hold invalid TT entries such as below. * 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) Remove the extra allocated space to avoid sending uninitialized entries for full table TT_RESPONSE in both batadv_send_other_tt_response() and batadv_send_my_tt_response(). Fixes: 7ea7b4a ("batman-adv: make the TT CRC logic VLAN specific") Signed-off-by: Remi Pommarel <[email protected]> Signed-off-by: Sven Eckelmann <[email protected]> Signed-off-by: Simon Wunderlich <[email protected]>
1 parent f2f7358 commit 8038806

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

net/batman-adv/translation-table.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,14 +2712,16 @@ static bool batadv_tt_global_valid(const void *entry_ptr,
27122712
*
27132713
* Fills the tvlv buff with the tt entries from the specified hash. If valid_cb
27142714
* is not provided then this becomes a no-op.
2715+
*
2716+
* Return: Remaining unused length in tvlv_buff.
27152717
*/
2716-
static void batadv_tt_tvlv_generate(struct batadv_priv *bat_priv,
2717-
struct batadv_hashtable *hash,
2718-
void *tvlv_buff, u16 tt_len,
2719-
bool (*valid_cb)(const void *,
2720-
const void *,
2721-
u8 *flags),
2722-
void *cb_data)
2718+
static u16 batadv_tt_tvlv_generate(struct batadv_priv *bat_priv,
2719+
struct batadv_hashtable *hash,
2720+
void *tvlv_buff, u16 tt_len,
2721+
bool (*valid_cb)(const void *,
2722+
const void *,
2723+
u8 *flags),
2724+
void *cb_data)
27232725
{
27242726
struct batadv_tt_common_entry *tt_common_entry;
27252727
struct batadv_tvlv_tt_change *tt_change;
@@ -2733,7 +2735,7 @@ static void batadv_tt_tvlv_generate(struct batadv_priv *bat_priv,
27332735
tt_change = tvlv_buff;
27342736

27352737
if (!valid_cb)
2736-
return;
2738+
return tt_len;
27372739

27382740
rcu_read_lock();
27392741
for (i = 0; i < hash->size; i++) {
@@ -2759,6 +2761,8 @@ static void batadv_tt_tvlv_generate(struct batadv_priv *bat_priv,
27592761
}
27602762
}
27612763
rcu_read_unlock();
2764+
2765+
return batadv_tt_len(tt_tot - tt_num_entries);
27622766
}
27632767

27642768
/**
@@ -3029,10 +3033,11 @@ static bool batadv_send_other_tt_response(struct batadv_priv *bat_priv,
30293033
goto out;
30303034

30313035
/* fill the rest of the tvlv with the real TT entries */
3032-
batadv_tt_tvlv_generate(bat_priv, bat_priv->tt.global_hash,
3033-
tt_change, tt_len,
3034-
batadv_tt_global_valid,
3035-
req_dst_orig_node);
3036+
tvlv_len -= batadv_tt_tvlv_generate(bat_priv,
3037+
bat_priv->tt.global_hash,
3038+
tt_change, tt_len,
3039+
batadv_tt_global_valid,
3040+
req_dst_orig_node);
30363041
}
30373042

30383043
/* Don't send the response, if larger than fragmented packet. */
@@ -3156,9 +3161,11 @@ static bool batadv_send_my_tt_response(struct batadv_priv *bat_priv,
31563161
goto out;
31573162

31583163
/* fill the rest of the tvlv with the real TT entries */
3159-
batadv_tt_tvlv_generate(bat_priv, bat_priv->tt.local_hash,
3160-
tt_change, tt_len,
3161-
batadv_tt_local_valid, NULL);
3164+
tvlv_len -= batadv_tt_tvlv_generate(bat_priv,
3165+
bat_priv->tt.local_hash,
3166+
tt_change, tt_len,
3167+
batadv_tt_local_valid,
3168+
NULL);
31623169
}
31633170

31643171
tvlv_tt_data->flags = BATADV_TT_RESPONSE;

0 commit comments

Comments
 (0)