batman-adv: 2015.0 bugfixes & stability updates
[feed/routing.git] / batman-adv / patches / 0009-batman-adv-fix-kernel-crash-due-to-missing-NULL-chec.patch
1 From 2c2dfd886a400057ccbc66f1507c94ed909d2a89 Mon Sep 17 00:00:00 2001
2 From: Marek Lindner <mareklindner@neomailbox.ch>
3 Date: Tue, 9 Jun 2015 21:24:36 +0800
4 Subject: [PATCH 09/17] batman-adv: fix kernel crash due to missing NULL checks
5
6 batadv_softif_vlan_get() may return NULL which has to be verified
7 by the caller.
8
9 Fixes: 9729d20 ("batman-adv: fix TT VLAN inconsistency on VLAN re-add")
10
11 Reported-by: Ryan Thompson <ryan@eero.com>
12 Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
13 Acked-by: Antonio Quartulli <antonio@meshcoding.com>
14 ---
15 soft-interface.c | 3 +++
16 translation-table.c | 19 +++++++++++++++----
17 2 files changed, 18 insertions(+), 4 deletions(-)
18
19 diff --git a/soft-interface.c b/soft-interface.c
20 index da89336..7841a4b 100644
21 --- a/soft-interface.c
22 +++ b/soft-interface.c
23 @@ -455,6 +455,9 @@ out:
24 */
25 void batadv_softif_vlan_free_ref(struct batadv_softif_vlan *vlan)
26 {
27 + if (!vlan)
28 + return;
29 +
30 if (atomic_dec_and_test(&vlan->refcount)) {
31 spin_lock_bh(&vlan->bat_priv->softif_vlan_list_lock);
32 hlist_del_rcu(&vlan->list);
33 diff --git a/translation-table.c b/translation-table.c
34 index e95a424..807a4e6 100644
35 --- a/translation-table.c
36 +++ b/translation-table.c
37 @@ -26,6 +26,7 @@
38 #include "bridge_loop_avoidance.h"
39 #include "multicast.h"
40
41 +#include <linux/bug.h>
42 #include <linux/crc32c.h>
43
44 /* hash class keys */
45 @@ -575,6 +576,9 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr,
46
47 /* increase the refcounter of the related vlan */
48 vlan = batadv_softif_vlan_get(bat_priv, vid);
49 + if (WARN(!vlan, "adding TT local entry %pM to non-existent VLAN %d",
50 + addr, BATADV_PRINT_VID(vid)))
51 + goto out;
52
53 batadv_dbg(BATADV_DBG_TT, bat_priv,
54 "Creating new local tt entry: %pM (vid: %d, ttvn: %d)\n",
55 @@ -1047,6 +1051,9 @@ uint16_t batadv_tt_local_remove(struct batadv_priv *bat_priv,
56
57 /* decrease the reference held for this vlan */
58 vlan = batadv_softif_vlan_get(bat_priv, vid);
59 + if (!vlan)
60 + goto out;
61 +
62 batadv_softif_vlan_free_ref(vlan);
63 batadv_softif_vlan_free_ref(vlan);
64
65 @@ -1147,8 +1154,10 @@ static void batadv_tt_local_table_free(struct batadv_priv *bat_priv)
66 /* decrease the reference held for this vlan */
67 vlan = batadv_softif_vlan_get(bat_priv,
68 tt_common_entry->vid);
69 - batadv_softif_vlan_free_ref(vlan);
70 - batadv_softif_vlan_free_ref(vlan);
71 + if (vlan) {
72 + batadv_softif_vlan_free_ref(vlan);
73 + batadv_softif_vlan_free_ref(vlan);
74 + }
75
76 batadv_tt_local_entry_free_ref(tt_local);
77 }
78 @@ -3188,8 +3197,10 @@ static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)
79
80 /* decrease the reference held for this vlan */
81 vlan = batadv_softif_vlan_get(bat_priv, tt_common->vid);
82 - batadv_softif_vlan_free_ref(vlan);
83 - batadv_softif_vlan_free_ref(vlan);
84 + if (vlan) {
85 + batadv_softif_vlan_free_ref(vlan);
86 + batadv_softif_vlan_free_ref(vlan);
87 + }
88
89 batadv_tt_local_entry_free_ref(tt_local);
90 }
91 --
92 2.1.4
93