diff options
author | Linus Lüssing <linus.luessing@web.de> | 2012-10-17 08:53:05 -0400 |
---|---|---|
committer | Antonio Quartulli <ordex@autistici.org> | 2012-10-18 12:17:31 -0400 |
commit | 7dac7b76b8db87fc79857a53a09730fb2148579b (patch) | |
tree | 4d03c5a61a0785e0e5cc696005459b20f7094bfe /net | |
parent | 7f112af40fecf5399b61e69ffc6b55a9d82789f7 (diff) |
batman-adv: Fix potential broadcast BLA-duplicate-check race condition
Threads in the bottom half of batadv_bla_check_bcast_duplist() might
otherwise for instance overwrite variables which other threads might
be using/reading at the same time in the top half, potentially
leading to messing up the bcast_duplist, possibly resulting in false
bridge loop avoidance duplicate check decisions.
Signed-off-by: Linus Lüssing <linus.luessing@web.de>
Acked-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Diffstat (limited to 'net')
-rw-r--r-- | net/batman-adv/bridge_loop_avoidance.c | 19 | ||||
-rw-r--r-- | net/batman-adv/types.h | 2 |
2 files changed, 16 insertions, 5 deletions
diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c index eebab20c7478..fd8d5afec0dd 100644 --- a/net/batman-adv/bridge_loop_avoidance.c +++ b/net/batman-adv/bridge_loop_avoidance.c | |||
@@ -1167,6 +1167,8 @@ int batadv_bla_init(struct batadv_priv *bat_priv) | |||
1167 | uint16_t crc; | 1167 | uint16_t crc; |
1168 | unsigned long entrytime; | 1168 | unsigned long entrytime; |
1169 | 1169 | ||
1170 | spin_lock_init(&bat_priv->bla.bcast_duplist_lock); | ||
1171 | |||
1170 | batadv_dbg(BATADV_DBG_BLA, bat_priv, "bla hash registering\n"); | 1172 | batadv_dbg(BATADV_DBG_BLA, bat_priv, "bla hash registering\n"); |
1171 | 1173 | ||
1172 | /* setting claim destination address */ | 1174 | /* setting claim destination address */ |
@@ -1226,7 +1228,7 @@ int batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv, | |||
1226 | struct batadv_bcast_packet *bcast_packet, | 1228 | struct batadv_bcast_packet *bcast_packet, |
1227 | int bcast_packet_len) | 1229 | int bcast_packet_len) |
1228 | { | 1230 | { |
1229 | int i, length, curr; | 1231 | int i, length, curr, ret = 0; |
1230 | uint8_t *content; | 1232 | uint8_t *content; |
1231 | uint16_t crc; | 1233 | uint16_t crc; |
1232 | struct batadv_bcast_duplist_entry *entry; | 1234 | struct batadv_bcast_duplist_entry *entry; |
@@ -1238,6 +1240,8 @@ int batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv, | |||
1238 | /* calculate the crc ... */ | 1240 | /* calculate the crc ... */ |
1239 | crc = crc16(0, content, length); | 1241 | crc = crc16(0, content, length); |
1240 | 1242 | ||
1243 | spin_lock_bh(&bat_priv->bla.bcast_duplist_lock); | ||
1244 | |||
1241 | for (i = 0; i < BATADV_DUPLIST_SIZE; i++) { | 1245 | for (i = 0; i < BATADV_DUPLIST_SIZE; i++) { |
1242 | curr = (bat_priv->bla.bcast_duplist_curr + i); | 1246 | curr = (bat_priv->bla.bcast_duplist_curr + i); |
1243 | curr %= BATADV_DUPLIST_SIZE; | 1247 | curr %= BATADV_DUPLIST_SIZE; |
@@ -1259,9 +1263,12 @@ int batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv, | |||
1259 | /* this entry seems to match: same crc, not too old, | 1263 | /* this entry seems to match: same crc, not too old, |
1260 | * and from another gw. therefore return 1 to forbid it. | 1264 | * and from another gw. therefore return 1 to forbid it. |
1261 | */ | 1265 | */ |
1262 | return 1; | 1266 | ret = 1; |
1267 | goto out; | ||
1263 | } | 1268 | } |
1264 | /* not found, add a new entry (overwrite the oldest entry) */ | 1269 | /* not found, add a new entry (overwrite the oldest entry) |
1270 | * and allow it, its the first occurence. | ||
1271 | */ | ||
1265 | curr = (bat_priv->bla.bcast_duplist_curr + BATADV_DUPLIST_SIZE - 1); | 1272 | curr = (bat_priv->bla.bcast_duplist_curr + BATADV_DUPLIST_SIZE - 1); |
1266 | curr %= BATADV_DUPLIST_SIZE; | 1273 | curr %= BATADV_DUPLIST_SIZE; |
1267 | entry = &bat_priv->bla.bcast_duplist[curr]; | 1274 | entry = &bat_priv->bla.bcast_duplist[curr]; |
@@ -1270,8 +1277,10 @@ int batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv, | |||
1270 | memcpy(entry->orig, bcast_packet->orig, ETH_ALEN); | 1277 | memcpy(entry->orig, bcast_packet->orig, ETH_ALEN); |
1271 | bat_priv->bla.bcast_duplist_curr = curr; | 1278 | bat_priv->bla.bcast_duplist_curr = curr; |
1272 | 1279 | ||
1273 | /* allow it, its the first occurence. */ | 1280 | out: |
1274 | return 0; | 1281 | spin_unlock_bh(&bat_priv->bla.bcast_duplist_lock); |
1282 | |||
1283 | return ret; | ||
1275 | } | 1284 | } |
1276 | 1285 | ||
1277 | 1286 | ||
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h index 2ed82caacdca..ac1e07a80454 100644 --- a/net/batman-adv/types.h +++ b/net/batman-adv/types.h | |||
@@ -205,6 +205,8 @@ struct batadv_priv_bla { | |||
205 | struct batadv_hashtable *backbone_hash; | 205 | struct batadv_hashtable *backbone_hash; |
206 | struct batadv_bcast_duplist_entry bcast_duplist[BATADV_DUPLIST_SIZE]; | 206 | struct batadv_bcast_duplist_entry bcast_duplist[BATADV_DUPLIST_SIZE]; |
207 | int bcast_duplist_curr; | 207 | int bcast_duplist_curr; |
208 | /* protects bcast_duplist and bcast_duplist_curr */ | ||
209 | spinlock_t bcast_duplist_lock; | ||
208 | struct batadv_bla_claim_dst claim_dest; | 210 | struct batadv_bla_claim_dst claim_dest; |
209 | struct delayed_work work; | 211 | struct delayed_work work; |
210 | }; | 212 | }; |