Skip to content

Commit

Permalink
batman-adv: Make TT capability changes atomic
Browse files Browse the repository at this point in the history
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: e17931d ("batman-adv: introduce capability initialization bitfield")
Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Antonio Quartulli <antonio@meshcoding.com>
  • Loading branch information
Linus Lüssing authored and Antonio Quartulli committed Aug 14, 2015
1 parent 4635469 commit ac4eebd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions net/batman-adv/translation-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "main.h"

#include <linux/atomic.h>
#include <linux/bitops.h>
#include <linux/bug.h>
#include <linux/byteorder/generic.h>
#include <linux/compiler.h>
Expand Down Expand Up @@ -1862,7 +1863,7 @@ void batadv_tt_global_del_orig(struct batadv_priv *bat_priv,
}
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,
Expand Down Expand Up @@ -2821,7 +2822,7 @@ static void _batadv_tt_update_changes(struct batadv_priv *bat_priv,
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,
Expand Down Expand Up @@ -3321,7 +3322,8 @@ static void batadv_tt_update_orig(struct batadv_priv *bat_priv,
bool has_tt_init;

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
* increased by one -> we can apply the attached changes
Expand Down
4 changes: 2 additions & 2 deletions net/batman-adv/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ struct batadv_orig_node {
struct hlist_node mcast_want_all_ipv6_node;
#endif
unsigned long capabilities;
uint8_t capa_initialized;
unsigned long capa_initialized;
atomic_t last_ttvn;
unsigned char *tt_buff;
int16_t tt_buff_len;
Expand Down Expand Up @@ -315,7 +315,7 @@ struct batadv_orig_node {
enum batadv_orig_capabilities {
BATADV_ORIG_CAPA_HAS_DAT,
BATADV_ORIG_CAPA_HAS_NC,
BATADV_ORIG_CAPA_HAS_TT = BIT(2),
BATADV_ORIG_CAPA_HAS_TT,
BATADV_ORIG_CAPA_HAS_MCAST = BIT(3),
};

Expand Down

0 comments on commit ac4eebd

Please sign in to comment.