Commit 1fa9989c authored by Linus Lüssing's avatar Linus Lüssing Committed by Luis Henriques

batman-adv: Make TT capability changes atomic

commit ac4eebd4 upstream.

Bitwise OR/AND assignments in C aren't guaranteed to be atomic. One
OGM handler might undo the set/clear of a specific bit from another
handler run in between.

Fix this by using the atomic set_bit()/clear_bit()/test_bit() functions.

Fixes: e17931d1 ("batman-adv: introduce capability initialization bitfield")
Signed-off-by: default avatarLinus Lüssing <linus.luessing@c0d3.blue>
Signed-off-by: default avatarMarek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: default avatarAntonio Quartulli <antonio@meshcoding.com>
[ luis: backported to 3.16: adjusted context ]
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 6a09dc38
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "bridge_loop_avoidance.h" #include "bridge_loop_avoidance.h"
#include "multicast.h" #include "multicast.h"
#include <linux/bitops.h>
#include <linux/crc32c.h> #include <linux/crc32c.h>
/* hash class keys */ /* hash class keys */
...@@ -1861,7 +1862,7 @@ void batadv_tt_global_del_orig(struct batadv_priv *bat_priv, ...@@ -1861,7 +1862,7 @@ void batadv_tt_global_del_orig(struct batadv_priv *bat_priv,
} }
spin_unlock_bh(list_lock); spin_unlock_bh(list_lock);
} }
orig_node->capa_initialized &= ~BATADV_ORIG_CAPA_HAS_TT; clear_bit(BATADV_ORIG_CAPA_HAS_TT, &orig_node->capa_initialized);
} }
static bool batadv_tt_global_to_purge(struct batadv_tt_global_entry *tt_global, static bool batadv_tt_global_to_purge(struct batadv_tt_global_entry *tt_global,
...@@ -2821,7 +2822,7 @@ static void _batadv_tt_update_changes(struct batadv_priv *bat_priv, ...@@ -2821,7 +2822,7 @@ static void _batadv_tt_update_changes(struct batadv_priv *bat_priv,
return; return;
} }
} }
orig_node->capa_initialized |= BATADV_ORIG_CAPA_HAS_TT; set_bit(BATADV_ORIG_CAPA_HAS_TT, &orig_node->capa_initialized);
} }
static void batadv_tt_fill_gtable(struct batadv_priv *bat_priv, static void batadv_tt_fill_gtable(struct batadv_priv *bat_priv,
...@@ -3323,7 +3324,8 @@ static void batadv_tt_update_orig(struct batadv_priv *bat_priv, ...@@ -3323,7 +3324,8 @@ static void batadv_tt_update_orig(struct batadv_priv *bat_priv,
bool has_tt_init; bool has_tt_init;
tt_vlan = (struct batadv_tvlv_tt_vlan_data *)tt_buff; tt_vlan = (struct batadv_tvlv_tt_vlan_data *)tt_buff;
has_tt_init = orig_node->capa_initialized & BATADV_ORIG_CAPA_HAS_TT; has_tt_init = test_bit(BATADV_ORIG_CAPA_HAS_TT,
&orig_node->capa_initialized);
/* orig table not initialised AND first diff is in the OGM OR the ttvn /* orig table not initialised AND first diff is in the OGM OR the ttvn
* increased by one -> we can apply the attached changes * increased by one -> we can apply the attached changes
......
...@@ -259,7 +259,7 @@ struct batadv_orig_node { ...@@ -259,7 +259,7 @@ struct batadv_orig_node {
struct hlist_node mcast_want_all_ipv6_node; struct hlist_node mcast_want_all_ipv6_node;
#endif #endif
unsigned long capabilities; unsigned long capabilities;
uint8_t capa_initialized; unsigned long capa_initialized;
atomic_t last_ttvn; atomic_t last_ttvn;
unsigned char *tt_buff; unsigned char *tt_buff;
int16_t tt_buff_len; int16_t tt_buff_len;
...@@ -300,7 +300,7 @@ struct batadv_orig_node { ...@@ -300,7 +300,7 @@ struct batadv_orig_node {
enum batadv_orig_capabilities { enum batadv_orig_capabilities {
BATADV_ORIG_CAPA_HAS_DAT, BATADV_ORIG_CAPA_HAS_DAT,
BATADV_ORIG_CAPA_HAS_NC, BATADV_ORIG_CAPA_HAS_NC,
BATADV_ORIG_CAPA_HAS_TT = BIT(2), BATADV_ORIG_CAPA_HAS_TT,
BATADV_ORIG_CAPA_HAS_MCAST = BIT(3), BATADV_ORIG_CAPA_HAS_MCAST = BIT(3),
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment