8fce2bf26f5366f7051fc0e271eaba26c1582f66
[feed/routing.git] / batman-adv / patches / 0054-batman-adv-Prevent-duplicated-global-TT-entry.patch
1 From: Sven Eckelmann <sven@narfation.org>
2 Date: Thu, 6 Sep 2018 14:35:27 +0200
3 Subject: [PATCH] batman-adv: Prevent duplicated global TT entry
4
5 The function batadv_tt_global_orig_entry_add is responsible for adding new
6 tt_orig_list_entry to the orig_list. It first checks whether the entry
7 already is in the list or not. If it is, then the creation of a new entry
8 is aborted.
9
10 But the lock for the list is only held when the list is really modified.
11 This could lead to duplicated entries because another context could create
12 an entry with the same key between the check and the list manipulation.
13
14 The check and the manipulation of the list must therefore be in the same
15 locked code section.
16
17 Fixes: c5eb5bb30321 ("batman-adv: add reference counting for type batadv_tt_orig_list_entry")
18 Signed-off-by: Sven Eckelmann <sven@narfation.org>
19 Acked-by: Marek Lindner <mareklindner@neomailbox.ch>
20
21 Origin: upstream, https://git.open-mesh.org/batman-adv.git/commit/79097255a1a3e1bd1949be309af941181fbc7b36
22 ---
23 net/batman-adv/translation-table.c | 6 ++++--
24 1 file changed, 4 insertions(+), 2 deletions(-)
25
26 diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
27 index 143a00f90d1d925aad7113f897d06f435f28dcd8..b32853cbab028f0a052492545bb803efdcdb0ff3 100644
28 --- a/net/batman-adv/translation-table.c
29 +++ b/net/batman-adv/translation-table.c
30 @@ -1603,6 +1603,8 @@ batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global,
31 {
32 struct batadv_tt_orig_list_entry *orig_entry;
33
34 + spin_lock_bh(&tt_global->list_lock);
35 +
36 orig_entry = batadv_tt_global_orig_entry_find(tt_global, orig_node);
37 if (orig_entry) {
38 /* refresh the ttvn: the current value could be a bogus one that
39 @@ -1625,11 +1627,9 @@ batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global,
40 orig_entry->flags = flags;
41 kref_init(&orig_entry->refcount);
42
43 - spin_lock_bh(&tt_global->list_lock);
44 kref_get(&orig_entry->refcount);
45 hlist_add_head_rcu(&orig_entry->list,
46 &tt_global->orig_list);
47 - spin_unlock_bh(&tt_global->list_lock);
48 atomic_inc(&tt_global->orig_list_count);
49
50 sync_flags:
51 @@ -1637,6 +1637,8 @@ sync_flags:
52 out:
53 if (orig_entry)
54 batadv_tt_orig_list_entry_put(orig_entry);
55 +
56 + spin_unlock_bh(&tt_global->list_lock);
57 }
58
59 /**