Skip to content

Commit e7136e4

Browse files
ecsvsimonwunderlich
authored andcommitted
batman-adv: Prevent duplicated global TT entry
The function batadv_tt_global_orig_entry_add is responsible for adding new tt_orig_list_entry to the orig_list. It first checks whether the entry already is in the list or not. If it is, then the creation of a new entry is aborted. But the lock for the list is only held when the list is really modified. This could lead to duplicated entries because another context could create an entry with the same key between the check and the list manipulation. The check and the manipulation of the list must therefore be in the same locked code section. Fixes: d657e62 ("batman-adv: add reference counting for type batadv_tt_orig_list_entry") Signed-off-by: Sven Eckelmann <[email protected]> Signed-off-by: Simon Wunderlich <[email protected]>
1 parent 94cb82f commit e7136e4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

net/batman-adv/translation-table.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,8 @@ batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global,
16131613
{
16141614
struct batadv_tt_orig_list_entry *orig_entry;
16151615

1616+
spin_lock_bh(&tt_global->list_lock);
1617+
16161618
orig_entry = batadv_tt_global_orig_entry_find(tt_global, orig_node);
16171619
if (orig_entry) {
16181620
/* refresh the ttvn: the current value could be a bogus one that
@@ -1635,18 +1637,18 @@ batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global,
16351637
orig_entry->flags = flags;
16361638
kref_init(&orig_entry->refcount);
16371639

1638-
spin_lock_bh(&tt_global->list_lock);
16391640
kref_get(&orig_entry->refcount);
16401641
hlist_add_head_rcu(&orig_entry->list,
16411642
&tt_global->orig_list);
1642-
spin_unlock_bh(&tt_global->list_lock);
16431643
atomic_inc(&tt_global->orig_list_count);
16441644

16451645
sync_flags:
16461646
batadv_tt_global_sync_flags(tt_global);
16471647
out:
16481648
if (orig_entry)
16491649
batadv_tt_orig_list_entry_put(orig_entry);
1650+
1651+
spin_unlock_bh(&tt_global->list_lock);
16501652
}
16511653

16521654
/**

0 commit comments

Comments
 (0)