]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.9.135/batman-adv-prevent-duplicated-tvlv-handler.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.9.135 / batman-adv-prevent-duplicated-tvlv-handler.patch
1 From foo@baz Thu Oct 18 11:11:32 CEST 2018
2 From: Sven Eckelmann <sven@narfation.org>
3 Date: Sun, 12 Aug 2018 21:04:45 +0200
4 Subject: batman-adv: Prevent duplicated tvlv handler
5
6 From: Sven Eckelmann <sven@narfation.org>
7
8 [ Upstream commit ae3cdc97dc10c7a3b31f297dab429bfb774c9ccb ]
9
10 The function batadv_tvlv_handler_register is responsible for adding new
11 tvlv_handler to the handler_list. It first checks whether the entry
12 already is in the list or not. If it is, then the creation of a new entry
13 is aborted.
14
15 But the lock for the list is only held when the list is really modified.
16 This could lead to duplicated entries because another context could create
17 an entry with the same key between the check and the list manipulation.
18
19 The check and the manipulation of the list must therefore be in the same
20 locked code section.
21
22 Fixes: ef26157747d4 ("batman-adv: tvlv - basic infrastructure")
23 Signed-off-by: Sven Eckelmann <sven@narfation.org>
24 Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
25 Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
26 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
27 ---
28 net/batman-adv/tvlv.c | 8 ++++++--
29 1 file changed, 6 insertions(+), 2 deletions(-)
30
31 --- a/net/batman-adv/tvlv.c
32 +++ b/net/batman-adv/tvlv.c
33 @@ -528,15 +528,20 @@ void batadv_tvlv_handler_register(struct
34 {
35 struct batadv_tvlv_handler *tvlv_handler;
36
37 + spin_lock_bh(&bat_priv->tvlv.handler_list_lock);
38 +
39 tvlv_handler = batadv_tvlv_handler_get(bat_priv, type, version);
40 if (tvlv_handler) {
41 + spin_unlock_bh(&bat_priv->tvlv.handler_list_lock);
42 batadv_tvlv_handler_put(tvlv_handler);
43 return;
44 }
45
46 tvlv_handler = kzalloc(sizeof(*tvlv_handler), GFP_ATOMIC);
47 - if (!tvlv_handler)
48 + if (!tvlv_handler) {
49 + spin_unlock_bh(&bat_priv->tvlv.handler_list_lock);
50 return;
51 + }
52
53 tvlv_handler->ogm_handler = optr;
54 tvlv_handler->unicast_handler = uptr;
55 @@ -546,7 +551,6 @@ void batadv_tvlv_handler_register(struct
56 kref_init(&tvlv_handler->refcount);
57 INIT_HLIST_NODE(&tvlv_handler->list);
58
59 - spin_lock_bh(&bat_priv->tvlv.handler_list_lock);
60 kref_get(&tvlv_handler->refcount);
61 hlist_add_head_rcu(&tvlv_handler->list, &bat_priv->tvlv.handler_list);
62 spin_unlock_bh(&bat_priv->tvlv.handler_list_lock);