Skip to content

Commit 95a428f

Browse files
committed
Merge tag 'batman-adv-fix-for-davem' of git://git.open-mesh.org/linux-merge
Antonio Quartulli says: ==================== Included changes: - prevent DAT from replying on behalf of local clients and confuse L2 bridges - fix crash on double list removal of TT objects (tt_local_entry) - fix crash due to missing NULL checks - initialize bw values for new GWs objects to prevent memory leak ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents d1163e9 + 27a4d5e commit 95a428f

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

net/batman-adv/distributed-arp-table.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,14 +1138,17 @@ void batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,
11381138
* @bat_priv: the bat priv with all the soft interface information
11391139
* @skb: packet to check
11401140
* @hdr_size: size of the encapsulation header
1141+
*
1142+
* Returns true if the packet was snooped and consumed by DAT. False if the
1143+
* packet has to be delivered to the interface
11411144
*/
11421145
bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
11431146
struct sk_buff *skb, int hdr_size)
11441147
{
11451148
uint16_t type;
11461149
__be32 ip_src, ip_dst;
11471150
uint8_t *hw_src, *hw_dst;
1148-
bool ret = false;
1151+
bool dropped = false;
11491152
unsigned short vid;
11501153

11511154
if (!atomic_read(&bat_priv->distributed_arp_table))
@@ -1174,12 +1177,17 @@ bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
11741177
/* if this REPLY is directed to a client of mine, let's deliver the
11751178
* packet to the interface
11761179
*/
1177-
ret = !batadv_is_my_client(bat_priv, hw_dst, vid);
1180+
dropped = !batadv_is_my_client(bat_priv, hw_dst, vid);
1181+
1182+
/* if this REPLY is sent on behalf of a client of mine, let's drop the
1183+
* packet because the client will reply by itself
1184+
*/
1185+
dropped |= batadv_is_my_client(bat_priv, hw_src, vid);
11781186
out:
1179-
if (ret)
1187+
if (dropped)
11801188
kfree_skb(skb);
1181-
/* if ret == false -> packet has to be delivered to the interface */
1182-
return ret;
1189+
/* if dropped == false -> deliver to the interface */
1190+
return dropped;
11831191
}
11841192

11851193
/**

net/batman-adv/gateway_client.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@ static void batadv_gw_node_add(struct batadv_priv *bat_priv,
439439

440440
INIT_HLIST_NODE(&gw_node->list);
441441
gw_node->orig_node = orig_node;
442+
gw_node->bandwidth_down = ntohl(gateway->bandwidth_down);
443+
gw_node->bandwidth_up = ntohl(gateway->bandwidth_up);
442444
atomic_set(&gw_node->refcount, 1);
443445

444446
spin_lock_bh(&bat_priv->gw.list_lock);

net/batman-adv/soft-interface.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ void batadv_interface_rx(struct net_device *soft_iface,
479479
*/
480480
void batadv_softif_vlan_free_ref(struct batadv_softif_vlan *vlan)
481481
{
482+
if (!vlan)
483+
return;
484+
482485
if (atomic_dec_and_test(&vlan->refcount)) {
483486
spin_lock_bh(&vlan->bat_priv->softif_vlan_list_lock);
484487
hlist_del_rcu(&vlan->list);

net/batman-adv/translation-table.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,9 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr,
594594

595595
/* increase the refcounter of the related vlan */
596596
vlan = batadv_softif_vlan_get(bat_priv, vid);
597+
if (WARN(!vlan, "adding TT local entry %pM to non-existent VLAN %d",
598+
addr, BATADV_PRINT_VID(vid)))
599+
goto out;
597600

598601
batadv_dbg(BATADV_DBG_TT, bat_priv,
599602
"Creating new local tt entry: %pM (vid: %d, ttvn: %d)\n",
@@ -1034,6 +1037,7 @@ uint16_t batadv_tt_local_remove(struct batadv_priv *bat_priv,
10341037
struct batadv_tt_local_entry *tt_local_entry;
10351038
uint16_t flags, curr_flags = BATADV_NO_FLAGS;
10361039
struct batadv_softif_vlan *vlan;
1040+
void *tt_entry_exists;
10371041

10381042
tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid);
10391043
if (!tt_local_entry)
@@ -1061,11 +1065,22 @@ uint16_t batadv_tt_local_remove(struct batadv_priv *bat_priv,
10611065
* immediately purge it
10621066
*/
10631067
batadv_tt_local_event(bat_priv, tt_local_entry, BATADV_TT_CLIENT_DEL);
1064-
hlist_del_rcu(&tt_local_entry->common.hash_entry);
1068+
1069+
tt_entry_exists = batadv_hash_remove(bat_priv->tt.local_hash,
1070+
batadv_compare_tt,
1071+
batadv_choose_tt,
1072+
&tt_local_entry->common);
1073+
if (!tt_entry_exists)
1074+
goto out;
1075+
1076+
/* extra call to free the local tt entry */
10651077
batadv_tt_local_entry_free_ref(tt_local_entry);
10661078

10671079
/* decrease the reference held for this vlan */
10681080
vlan = batadv_softif_vlan_get(bat_priv, vid);
1081+
if (!vlan)
1082+
goto out;
1083+
10691084
batadv_softif_vlan_free_ref(vlan);
10701085
batadv_softif_vlan_free_ref(vlan);
10711086

@@ -1166,8 +1181,10 @@ static void batadv_tt_local_table_free(struct batadv_priv *bat_priv)
11661181
/* decrease the reference held for this vlan */
11671182
vlan = batadv_softif_vlan_get(bat_priv,
11681183
tt_common_entry->vid);
1169-
batadv_softif_vlan_free_ref(vlan);
1170-
batadv_softif_vlan_free_ref(vlan);
1184+
if (vlan) {
1185+
batadv_softif_vlan_free_ref(vlan);
1186+
batadv_softif_vlan_free_ref(vlan);
1187+
}
11711188

11721189
batadv_tt_local_entry_free_ref(tt_local);
11731190
}
@@ -3207,8 +3224,10 @@ static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)
32073224

32083225
/* decrease the reference held for this vlan */
32093226
vlan = batadv_softif_vlan_get(bat_priv, tt_common->vid);
3210-
batadv_softif_vlan_free_ref(vlan);
3211-
batadv_softif_vlan_free_ref(vlan);
3227+
if (vlan) {
3228+
batadv_softif_vlan_free_ref(vlan);
3229+
batadv_softif_vlan_free_ref(vlan);
3230+
}
32123231

32133232
batadv_tt_local_entry_free_ref(tt_local);
32143233
}

0 commit comments

Comments
 (0)