aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Eckelmann <sven@narfation.org>2017-12-26 09:14:01 -0500
committerSimon Wunderlich <sw@simonwunderlich.de>2018-02-25 14:19:34 -0500
commitf22e08932c2960f29b5e828e745c9f3fb7c1bb86 (patch)
treed4c971d4feef6c4553cb659cada3cab0b159ed17
parentfce672db548ff19e76a08a32a829544617229bc2 (diff)
batman-adv: Fix internal interface indices types
batman-adv uses internal indices for each enabled and active interface. It is currently used by the B.A.T.M.A.N. IV algorithm to identifify the correct position in the ogm_cnt bitmaps. The type for the number of enabled interfaces (which defines the next interface index) was set to char. This type can be (depending on the architecture) either signed (limiting batman-adv to 127 active slave interfaces) or unsigned (limiting batman-adv to 255 active slave interfaces). This limit was not correctly checked when an interface was enabled and thus an overflow happened. This was only catched on systems with the signed char type when the B.A.T.M.A.N. IV code tried to resize its counter arrays with a negative size. The if_num interface index was only a s16 and therefore significantly smaller than the ifindex (int) used by the code net code. Both &batadv_hard_iface->if_num and &batadv_priv->num_ifaces must be (unsigned) int to support the same number of slave interfaces as the net core code. And the interface activation code must check the number of active slave interfaces to avoid integer overflows. Fixes: c6c8fea29769 ("net: Add batman-adv meshing protocol") Signed-off-by: Sven Eckelmann <sven@narfation.org> Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
-rw-r--r--net/batman-adv/bat_iv_ogm.c24
-rw-r--r--net/batman-adv/hard-interface.c9
-rw-r--r--net/batman-adv/originator.c4
-rw-r--r--net/batman-adv/originator.h4
-rw-r--r--net/batman-adv/types.h11
5 files changed, 31 insertions, 21 deletions
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 8f64439647e3..99abeadf416e 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -157,7 +157,7 @@ static void batadv_iv_ogm_orig_free(struct batadv_orig_node *orig_node)
157 * Return: 0 on success, a negative error code otherwise. 157 * Return: 0 on success, a negative error code otherwise.
158 */ 158 */
159static int batadv_iv_ogm_orig_add_if(struct batadv_orig_node *orig_node, 159static int batadv_iv_ogm_orig_add_if(struct batadv_orig_node *orig_node,
160 int max_if_num) 160 unsigned int max_if_num)
161{ 161{
162 void *data_ptr; 162 void *data_ptr;
163 size_t old_size; 163 size_t old_size;
@@ -201,7 +201,8 @@ unlock:
201 */ 201 */
202static void 202static void
203batadv_iv_ogm_drop_bcast_own_entry(struct batadv_orig_node *orig_node, 203batadv_iv_ogm_drop_bcast_own_entry(struct batadv_orig_node *orig_node,
204 int max_if_num, int del_if_num) 204 unsigned int max_if_num,
205 unsigned int del_if_num)
205{ 206{
206 size_t chunk_size; 207 size_t chunk_size;
207 size_t if_offset; 208 size_t if_offset;
@@ -239,7 +240,8 @@ batadv_iv_ogm_drop_bcast_own_entry(struct batadv_orig_node *orig_node,
239 */ 240 */
240static void 241static void
241batadv_iv_ogm_drop_bcast_own_sum_entry(struct batadv_orig_node *orig_node, 242batadv_iv_ogm_drop_bcast_own_sum_entry(struct batadv_orig_node *orig_node,
242 int max_if_num, int del_if_num) 243 unsigned int max_if_num,
244 unsigned int del_if_num)
243{ 245{
244 size_t if_offset; 246 size_t if_offset;
245 void *data_ptr; 247 void *data_ptr;
@@ -276,7 +278,8 @@ batadv_iv_ogm_drop_bcast_own_sum_entry(struct batadv_orig_node *orig_node,
276 * Return: 0 on success, a negative error code otherwise. 278 * Return: 0 on success, a negative error code otherwise.
277 */ 279 */
278static int batadv_iv_ogm_orig_del_if(struct batadv_orig_node *orig_node, 280static int batadv_iv_ogm_orig_del_if(struct batadv_orig_node *orig_node,
279 int max_if_num, int del_if_num) 281 unsigned int max_if_num,
282 unsigned int del_if_num)
280{ 283{
281 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock); 284 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
282 285
@@ -311,7 +314,8 @@ static struct batadv_orig_node *
311batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const u8 *addr) 314batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const u8 *addr)
312{ 315{
313 struct batadv_orig_node *orig_node; 316 struct batadv_orig_node *orig_node;
314 int size, hash_added; 317 int hash_added;
318 size_t size;
315 319
316 orig_node = batadv_orig_hash_find(bat_priv, addr); 320 orig_node = batadv_orig_hash_find(bat_priv, addr);
317 if (orig_node) 321 if (orig_node)
@@ -893,7 +897,7 @@ batadv_iv_ogm_slide_own_bcast_window(struct batadv_hard_iface *hard_iface)
893 u32 i; 897 u32 i;
894 size_t word_index; 898 size_t word_index;
895 u8 *w; 899 u8 *w;
896 int if_num; 900 unsigned int if_num;
897 901
898 for (i = 0; i < hash->size; i++) { 902 for (i = 0; i < hash->size; i++) {
899 head = &hash->table[i]; 903 head = &hash->table[i];
@@ -1023,7 +1027,7 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,
1023 struct batadv_neigh_node *tmp_neigh_node = NULL; 1027 struct batadv_neigh_node *tmp_neigh_node = NULL;
1024 struct batadv_neigh_node *router = NULL; 1028 struct batadv_neigh_node *router = NULL;
1025 struct batadv_orig_node *orig_node_tmp; 1029 struct batadv_orig_node *orig_node_tmp;
1026 int if_num; 1030 unsigned int if_num;
1027 u8 sum_orig, sum_neigh; 1031 u8 sum_orig, sum_neigh;
1028 u8 *neigh_addr; 1032 u8 *neigh_addr;
1029 u8 tq_avg; 1033 u8 tq_avg;
@@ -1182,7 +1186,7 @@ static bool batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node,
1182 u8 total_count; 1186 u8 total_count;
1183 u8 orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own; 1187 u8 orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own;
1184 unsigned int neigh_rq_inv_cube, neigh_rq_max_cube; 1188 unsigned int neigh_rq_inv_cube, neigh_rq_max_cube;
1185 int if_num; 1189 unsigned int if_num;
1186 unsigned int tq_asym_penalty, inv_asym_penalty; 1190 unsigned int tq_asym_penalty, inv_asym_penalty;
1187 unsigned int combined_tq; 1191 unsigned int combined_tq;
1188 unsigned int tq_iface_penalty; 1192 unsigned int tq_iface_penalty;
@@ -1702,9 +1706,9 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
1702 1706
1703 if (is_my_orig) { 1707 if (is_my_orig) {
1704 unsigned long *word; 1708 unsigned long *word;
1705 int offset; 1709 size_t offset;
1706 s32 bit_pos; 1710 s32 bit_pos;
1707 s16 if_num; 1711 unsigned int if_num;
1708 u8 *weight; 1712 u8 *weight;
1709 1713
1710 orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv, 1714 orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv,
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 5f186bff284a..68b54a39c51d 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -763,6 +763,11 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
763 hard_iface->soft_iface = soft_iface; 763 hard_iface->soft_iface = soft_iface;
764 bat_priv = netdev_priv(hard_iface->soft_iface); 764 bat_priv = netdev_priv(hard_iface->soft_iface);
765 765
766 if (bat_priv->num_ifaces >= UINT_MAX) {
767 ret = -ENOSPC;
768 goto err_dev;
769 }
770
766 ret = netdev_master_upper_dev_link(hard_iface->net_dev, 771 ret = netdev_master_upper_dev_link(hard_iface->net_dev,
767 soft_iface, NULL, NULL, NULL); 772 soft_iface, NULL, NULL, NULL);
768 if (ret) 773 if (ret)
@@ -876,7 +881,7 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface,
876 batadv_hardif_recalc_extra_skbroom(hard_iface->soft_iface); 881 batadv_hardif_recalc_extra_skbroom(hard_iface->soft_iface);
877 882
878 /* nobody uses this interface anymore */ 883 /* nobody uses this interface anymore */
879 if (!bat_priv->num_ifaces) { 884 if (bat_priv->num_ifaces == 0) {
880 batadv_gw_check_client_stop(bat_priv); 885 batadv_gw_check_client_stop(bat_priv);
881 886
882 if (autodel == BATADV_IF_CLEANUP_AUTO) 887 if (autodel == BATADV_IF_CLEANUP_AUTO)
@@ -912,7 +917,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
912 if (ret) 917 if (ret)
913 goto free_if; 918 goto free_if;
914 919
915 hard_iface->if_num = -1; 920 hard_iface->if_num = 0;
916 hard_iface->net_dev = net_dev; 921 hard_iface->net_dev = net_dev;
917 hard_iface->soft_iface = NULL; 922 hard_iface->soft_iface = NULL;
918 hard_iface->if_status = BATADV_IF_NOT_IN_USE; 923 hard_iface->if_status = BATADV_IF_NOT_IN_USE;
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 58a7d9274435..74782426bb77 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -1569,7 +1569,7 @@ int batadv_orig_dump(struct sk_buff *msg, struct netlink_callback *cb)
1569 * Return: 0 on success or negative error number in case of failure 1569 * Return: 0 on success or negative error number in case of failure
1570 */ 1570 */
1571int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface, 1571int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface,
1572 int max_if_num) 1572 unsigned int max_if_num)
1573{ 1573{
1574 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); 1574 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
1575 struct batadv_algo_ops *bao = bat_priv->algo_ops; 1575 struct batadv_algo_ops *bao = bat_priv->algo_ops;
@@ -1611,7 +1611,7 @@ err:
1611 * Return: 0 on success or negative error number in case of failure 1611 * Return: 0 on success or negative error number in case of failure
1612 */ 1612 */
1613int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface, 1613int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface,
1614 int max_if_num) 1614 unsigned int max_if_num)
1615{ 1615{
1616 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); 1616 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
1617 struct batadv_hashtable *hash = bat_priv->orig_hash; 1617 struct batadv_hashtable *hash = bat_priv->orig_hash;
diff --git a/net/batman-adv/originator.h b/net/batman-adv/originator.h
index 8e543a3cdc6c..15d896b2de6f 100644
--- a/net/batman-adv/originator.h
+++ b/net/batman-adv/originator.h
@@ -73,9 +73,9 @@ int batadv_orig_seq_print_text(struct seq_file *seq, void *offset);
73int batadv_orig_dump(struct sk_buff *msg, struct netlink_callback *cb); 73int batadv_orig_dump(struct sk_buff *msg, struct netlink_callback *cb);
74int batadv_orig_hardif_seq_print_text(struct seq_file *seq, void *offset); 74int batadv_orig_hardif_seq_print_text(struct seq_file *seq, void *offset);
75int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface, 75int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface,
76 int max_if_num); 76 unsigned int max_if_num);
77int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface, 77int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface,
78 int max_if_num); 78 unsigned int max_if_num);
79struct batadv_orig_node_vlan * 79struct batadv_orig_node_vlan *
80batadv_orig_node_vlan_new(struct batadv_orig_node *orig_node, 80batadv_orig_node_vlan_new(struct batadv_orig_node *orig_node,
81 unsigned short vid); 81 unsigned short vid);
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index bb1578410e0c..a5aa6d61f4e2 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -167,7 +167,7 @@ struct batadv_hard_iface {
167 struct list_head list; 167 struct list_head list;
168 168
169 /** @if_num: identificator of the interface */ 169 /** @if_num: identificator of the interface */
170 s16 if_num; 170 unsigned int if_num;
171 171
172 /** @if_status: status of the interface for batman-adv */ 172 /** @if_status: status of the interface for batman-adv */
173 char if_status; 173 char if_status;
@@ -1596,7 +1596,7 @@ struct batadv_priv {
1596 atomic_t batman_queue_left; 1596 atomic_t batman_queue_left;
1597 1597
1598 /** @num_ifaces: number of interfaces assigned to this mesh interface */ 1598 /** @num_ifaces: number of interfaces assigned to this mesh interface */
1599 char num_ifaces; 1599 unsigned int num_ifaces;
1600 1600
1601 /** @mesh_obj: kobject for sysfs mesh subdirectory */ 1601 /** @mesh_obj: kobject for sysfs mesh subdirectory */
1602 struct kobject *mesh_obj; 1602 struct kobject *mesh_obj;
@@ -2186,15 +2186,16 @@ struct batadv_algo_orig_ops {
2186 * orig_node due to a new hard-interface being added into the mesh 2186 * orig_node due to a new hard-interface being added into the mesh
2187 * (optional) 2187 * (optional)
2188 */ 2188 */
2189 int (*add_if)(struct batadv_orig_node *orig_node, int max_if_num); 2189 int (*add_if)(struct batadv_orig_node *orig_node,
2190 unsigned int max_if_num);
2190 2191
2191 /** 2192 /**
2192 * @del_if: ask the routing algorithm to apply the needed changes to the 2193 * @del_if: ask the routing algorithm to apply the needed changes to the
2193 * orig_node due to an hard-interface being removed from the mesh 2194 * orig_node due to an hard-interface being removed from the mesh
2194 * (optional) 2195 * (optional)
2195 */ 2196 */
2196 int (*del_if)(struct batadv_orig_node *orig_node, int max_if_num, 2197 int (*del_if)(struct batadv_orig_node *orig_node,
2197 int del_if_num); 2198 unsigned int max_if_num, unsigned int del_if_num);
2198 2199
2199#ifdef CONFIG_BATMAN_ADV_DEBUGFS 2200#ifdef CONFIG_BATMAN_ADV_DEBUGFS
2200 /** @print: print the originator table (optional) */ 2201 /** @print: print the originator table (optional) */