Skip to content

Commit 2ea8a02

Browse files
committed
Merge tag 'batadv-net-pullrequest-20240621' of git://git.open-mesh.org/linux-merge
Simon Wunderlich says: ==================== Here are some batman-adv bugfixes: - Don't accept TT entries for out-of-spec VIDs, by Sven Eckelmann - Revert "batman-adv: prefer kfree_rcu() over call_rcu() with free-only callbacks", by Linus Lüssing * tag 'batadv-net-pullrequest-20240621' of git://git.open-mesh.org/linux-merge: Revert "batman-adv: prefer kfree_rcu() over call_rcu() with free-only callbacks" batman-adv: Don't accept TT entries for out-of-spec VIDs ==================== Link: https://patch.msgid.link/20240621143915.49137-1-sw@simonwunderlich.de Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents a38b800 + 6bfff35 commit 2ea8a02

2 files changed

Lines changed: 71 additions & 3 deletions

File tree

net/batman-adv/originator.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/errno.h>
1313
#include <linux/etherdevice.h>
1414
#include <linux/gfp.h>
15+
#include <linux/if_vlan.h>
1516
#include <linux/jiffies.h>
1617
#include <linux/kref.h>
1718
#include <linux/list.h>
@@ -131,6 +132,29 @@ batadv_orig_node_vlan_get(struct batadv_orig_node *orig_node,
131132
return vlan;
132133
}
133134

135+
/**
136+
* batadv_vlan_id_valid() - check if vlan id is in valid batman-adv encoding
137+
* @vid: the VLAN identifier
138+
*
139+
* Return: true when either no vlan is set or if VLAN is in correct range,
140+
* false otherwise
141+
*/
142+
static bool batadv_vlan_id_valid(unsigned short vid)
143+
{
144+
unsigned short non_vlan = vid & ~(BATADV_VLAN_HAS_TAG | VLAN_VID_MASK);
145+
146+
if (vid == 0)
147+
return true;
148+
149+
if (!(vid & BATADV_VLAN_HAS_TAG))
150+
return false;
151+
152+
if (non_vlan)
153+
return false;
154+
155+
return true;
156+
}
157+
134158
/**
135159
* batadv_orig_node_vlan_new() - search and possibly create an orig_node_vlan
136160
* object
@@ -149,6 +173,9 @@ batadv_orig_node_vlan_new(struct batadv_orig_node *orig_node,
149173
{
150174
struct batadv_orig_node_vlan *vlan;
151175

176+
if (!batadv_vlan_id_valid(vid))
177+
return NULL;
178+
152179
spin_lock_bh(&orig_node->vlan_list_lock);
153180

154181
/* first look if an object for this vid already exists */

net/batman-adv/translation-table.c

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,20 @@ batadv_tt_global_hash_find(struct batadv_priv *bat_priv, const u8 *addr,
208208
return tt_global_entry;
209209
}
210210

211+
/**
212+
* batadv_tt_local_entry_free_rcu() - free the tt_local_entry
213+
* @rcu: rcu pointer of the tt_local_entry
214+
*/
215+
static void batadv_tt_local_entry_free_rcu(struct rcu_head *rcu)
216+
{
217+
struct batadv_tt_local_entry *tt_local_entry;
218+
219+
tt_local_entry = container_of(rcu, struct batadv_tt_local_entry,
220+
common.rcu);
221+
222+
kmem_cache_free(batadv_tl_cache, tt_local_entry);
223+
}
224+
211225
/**
212226
* batadv_tt_local_entry_release() - release tt_local_entry from lists and queue
213227
* for free after rcu grace period
@@ -222,7 +236,7 @@ static void batadv_tt_local_entry_release(struct kref *ref)
222236

223237
batadv_softif_vlan_put(tt_local_entry->vlan);
224238

225-
kfree_rcu(tt_local_entry, common.rcu);
239+
call_rcu(&tt_local_entry->common.rcu, batadv_tt_local_entry_free_rcu);
226240
}
227241

228242
/**
@@ -240,6 +254,20 @@ batadv_tt_local_entry_put(struct batadv_tt_local_entry *tt_local_entry)
240254
batadv_tt_local_entry_release);
241255
}
242256

257+
/**
258+
* batadv_tt_global_entry_free_rcu() - free the tt_global_entry
259+
* @rcu: rcu pointer of the tt_global_entry
260+
*/
261+
static void batadv_tt_global_entry_free_rcu(struct rcu_head *rcu)
262+
{
263+
struct batadv_tt_global_entry *tt_global_entry;
264+
265+
tt_global_entry = container_of(rcu, struct batadv_tt_global_entry,
266+
common.rcu);
267+
268+
kmem_cache_free(batadv_tg_cache, tt_global_entry);
269+
}
270+
243271
/**
244272
* batadv_tt_global_entry_release() - release tt_global_entry from lists and
245273
* queue for free after rcu grace period
@@ -254,7 +282,7 @@ void batadv_tt_global_entry_release(struct kref *ref)
254282

255283
batadv_tt_global_del_orig_list(tt_global_entry);
256284

257-
kfree_rcu(tt_global_entry, common.rcu);
285+
call_rcu(&tt_global_entry->common.rcu, batadv_tt_global_entry_free_rcu);
258286
}
259287

260288
/**
@@ -379,6 +407,19 @@ static void batadv_tt_global_size_dec(struct batadv_orig_node *orig_node,
379407
batadv_tt_global_size_mod(orig_node, vid, -1);
380408
}
381409

410+
/**
411+
* batadv_tt_orig_list_entry_free_rcu() - free the orig_entry
412+
* @rcu: rcu pointer of the orig_entry
413+
*/
414+
static void batadv_tt_orig_list_entry_free_rcu(struct rcu_head *rcu)
415+
{
416+
struct batadv_tt_orig_list_entry *orig_entry;
417+
418+
orig_entry = container_of(rcu, struct batadv_tt_orig_list_entry, rcu);
419+
420+
kmem_cache_free(batadv_tt_orig_cache, orig_entry);
421+
}
422+
382423
/**
383424
* batadv_tt_orig_list_entry_release() - release tt orig entry from lists and
384425
* queue for free after rcu grace period
@@ -392,7 +433,7 @@ static void batadv_tt_orig_list_entry_release(struct kref *ref)
392433
refcount);
393434

394435
batadv_orig_node_put(orig_entry->orig_node);
395-
kfree_rcu(orig_entry, rcu);
436+
call_rcu(&orig_entry->rcu, batadv_tt_orig_list_entry_free_rcu);
396437
}
397438

398439
/**

0 commit comments

Comments
 (0)