|
| 1 | +From: Remi Pommarel < [email protected]> |
| 2 | +Date: Fri, 22 Nov 2024 16:52:49 +0100 |
| 3 | +Subject: batman-adv: Remove uninitialized data in full table TT response |
| 4 | + |
| 5 | +The number of entries filled by batadv_tt_tvlv_generate() can be less |
| 6 | +than initially expected in batadv_tt_prepare_tvlv_{global,local}_data() |
| 7 | +(changes can be removed by batadv_tt_local_event() in ADD+DEL sequence |
| 8 | +in the meantime as the lock held during the whole tvlv global/local data |
| 9 | +generation). |
| 10 | + |
| 11 | +Thus tvlv_len could be bigger than the actual TT entry size that need |
| 12 | +to be sent so full table TT_RESPONSE could hold invalid TT entries such |
| 13 | +as below. |
| 14 | + |
| 15 | + * 00:00:00:00:00:00 -1 [....] ( 0) 88:12:4e:ad:7e:ba (179) (0x45845380) |
| 16 | + * 00:00:00:00:78:79 4092 [.W..] ( 0) 88:12:4e:ad:7e:3c (145) (0x8ebadb8b) |
| 17 | + |
| 18 | +Remove the extra allocated space to avoid sending uninitialized entries |
| 19 | +for full table TT_RESPONSE in both batadv_send_other_tt_response() and |
| 20 | +batadv_send_my_tt_response(). |
| 21 | + |
| 22 | +Fixes: 21a57f6e7a3b ("batman-adv: make the TT CRC logic VLAN specific") |
| 23 | +Signed-off-by: Remi Pommarel < [email protected]> |
| 24 | +Signed-off-by: Sven Eckelmann < [email protected]> |
| 25 | +Origin: upstream, https://git.open-mesh.org/batman-adv.git/commit/095c3965bdc29e43546a9cdd21f179f952e01f48 |
| 26 | + |
| 27 | +--- a/net/batman-adv/translation-table.c |
| 28 | ++++ b/net/batman-adv/translation-table.c |
| 29 | +@@ -2754,14 +2754,16 @@ static bool batadv_tt_global_valid(const |
| 30 | + * |
| 31 | + * Fills the tvlv buff with the tt entries from the specified hash. If valid_cb |
| 32 | + * is not provided then this becomes a no-op. |
| 33 | ++ * |
| 34 | ++ * Return: Remaining unused length in tvlv_buff. |
| 35 | + */ |
| 36 | +-static void batadv_tt_tvlv_generate(struct batadv_priv *bat_priv, |
| 37 | +- struct batadv_hashtable *hash, |
| 38 | +- void *tvlv_buff, u16 tt_len, |
| 39 | +- bool (*valid_cb)(const void *, |
| 40 | +- const void *, |
| 41 | +- u8 *flags), |
| 42 | +- void *cb_data) |
| 43 | ++static u16 batadv_tt_tvlv_generate(struct batadv_priv *bat_priv, |
| 44 | ++ struct batadv_hashtable *hash, |
| 45 | ++ void *tvlv_buff, u16 tt_len, |
| 46 | ++ bool (*valid_cb)(const void *, |
| 47 | ++ const void *, |
| 48 | ++ u8 *flags), |
| 49 | ++ void *cb_data) |
| 50 | + { |
| 51 | + struct batadv_tt_common_entry *tt_common_entry; |
| 52 | + struct batadv_tvlv_tt_change *tt_change; |
| 53 | +@@ -2775,7 +2777,7 @@ static void batadv_tt_tvlv_generate(stru |
| 54 | + tt_change = tvlv_buff; |
| 55 | + |
| 56 | + if (!valid_cb) |
| 57 | +- return; |
| 58 | ++ return tt_len; |
| 59 | + |
| 60 | + rcu_read_lock(); |
| 61 | + for (i = 0; i < hash->size; i++) { |
| 62 | +@@ -2801,6 +2803,8 @@ static void batadv_tt_tvlv_generate(stru |
| 63 | + } |
| 64 | + } |
| 65 | + rcu_read_unlock(); |
| 66 | ++ |
| 67 | ++ return batadv_tt_len(tt_tot - tt_num_entries); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | +@@ -3076,10 +3080,11 @@ static bool batadv_send_other_tt_respons |
| 72 | + goto out; |
| 73 | + |
| 74 | + /* fill the rest of the tvlv with the real TT entries */ |
| 75 | +- batadv_tt_tvlv_generate(bat_priv, bat_priv->tt.global_hash, |
| 76 | +- tt_change, tt_len, |
| 77 | +- batadv_tt_global_valid, |
| 78 | +- req_dst_orig_node); |
| 79 | ++ tvlv_len -= batadv_tt_tvlv_generate(bat_priv, |
| 80 | ++ bat_priv->tt.global_hash, |
| 81 | ++ tt_change, tt_len, |
| 82 | ++ batadv_tt_global_valid, |
| 83 | ++ req_dst_orig_node); |
| 84 | + } |
| 85 | + |
| 86 | + /* Don't send the response, if larger than fragmented packet. */ |
| 87 | +@@ -3203,9 +3208,11 @@ static bool batadv_send_my_tt_response(s |
| 88 | + goto out; |
| 89 | + |
| 90 | + /* fill the rest of the tvlv with the real TT entries */ |
| 91 | +- batadv_tt_tvlv_generate(bat_priv, bat_priv->tt.local_hash, |
| 92 | +- tt_change, tt_len, |
| 93 | +- batadv_tt_local_valid, NULL); |
| 94 | ++ tvlv_len -= batadv_tt_tvlv_generate(bat_priv, |
| 95 | ++ bat_priv->tt.local_hash, |
| 96 | ++ tt_change, tt_len, |
| 97 | ++ batadv_tt_local_valid, |
| 98 | ++ NULL); |
| 99 | + } |
| 100 | + |
| 101 | + tvlv_tt_data->flags = BATADV_TT_RESPONSE; |
0 commit comments