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
6 batadv_softif_vlan_get() may return NULL which has to be verified
9 Fixes: 9729d20 ("batman-adv: fix TT VLAN inconsistency on VLAN re-add")
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>
15 soft-interface.c | 3 +++
16 translation-table.c | 19 +++++++++++++++----
17 2 files changed, 18 insertions(+), 4 deletions(-)
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:
25 void batadv_softif_vlan_free_ref(struct batadv_softif_vlan *vlan)
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
38 #include "bridge_loop_avoidance.h"
39 #include "multicast.h"
41 +#include <linux/bug.h>
42 #include <linux/crc32c.h>
45 @@ -575,6 +576,9 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr,
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)))
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,
57 /* decrease the reference held for this vlan */
58 vlan = batadv_softif_vlan_get(bat_priv, vid);
62 batadv_softif_vlan_free_ref(vlan);
63 batadv_softif_vlan_free_ref(vlan);
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);
72 + batadv_softif_vlan_free_ref(vlan);
73 + batadv_softif_vlan_free_ref(vlan);
76 batadv_tt_local_entry_free_ref(tt_local);
78 @@ -3188,8 +3197,10 @@ static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)
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);
85 + batadv_softif_vlan_free_ref(vlan);
86 + batadv_softif_vlan_free_ref(vlan);
89 batadv_tt_local_entry_free_ref(tt_local);