pull request: batman-adv 2026-05-08
Subsystems (4)
Simon Wunderlich
maintainercover pull request: batman-adv 2026-05-08
Dear net maintainers,
here are a couple of bugfixes for batman-adv which we would like to have integrated into net.
Please pull or let me know of any problem!
Thank you,
Simon
The following changes since commit 1f5ffc672165ff851063a5fd044b727ab2517ae3:
Fix mismerge of the arm64 / timer-core interrupt handling changes (2026-04-14 23:03:02 -0700)
are available in the Git repository at:
https://git.open-mesh.org/batadv.git tags/batadv-net-pullrequest-20260508
for you to fetch changes up to ba9d20ee9076dac32c371116bacbe72480eb356c:
batman-adv: bla: put backbone reference on failed claim hash insert (2026-05-08 14:29:02 +0200)
----------------------------------------------------------------
Here are some batman-adv bugfixes:
- fix integer overflow on buff_pos, by Lyes Bourennani
- fix invalid tp_meter access during teardown, by Jiexun Wang (2 patches)
- stop caching unowned originator pointers in BAT IV, by Jiexun Wang
- tp_meter: fix tp_num leak on kmalloc failure, by Sven Eckelmann
- fix BLA refcounting issues, by Sven Eckelmann (3 patches)
----------------------------------------------------------------
Jiexun Wang (3):
batman-adv: reject new tp_meter sessions during teardown
batman-adv: stop tp_meter sessions during mesh teardown
batman-adv: stop caching unowned originator pointers in BAT IV
Lyes Bourennani (1):
batman-adv: fix integer overflow on buff_pos
Sven Eckelmann (4):
batman-adv: tp_meter: fix tp_num leak on kmalloc failure
batman-adv: bla: prevent use-after-free when deleting claims
batman-adv: bla: only purge non-released claims
batman-adv: bla: put backbone reference on failed claim hash insert
net/batman-adv/bat_iv_ogm.c | 85 +++++++++++++++++------- net/batman-adv/bridge_loop_avoidance.c | 11 +++- net/batman-adv/main.c | 1 + net/batman-adv/tp_meter.c | 116 +++++++++++++++++++++++++++------ net/batman-adv/tp_meter.h | 1 + net/batman-adv/types.h | 4 ++ 6 files changed, 172 insertions(+), 46 deletions(-)
Simon Wunderlich
maintainerPATCH 1/8 batman-adv: fix integer overflow on buff_pos
From: Lyes Bourennani <[email protected]>
Fixing an integer overflow present in batadv_iv_ogm_send_to_if. The size check is done using the int type in batadv_iv_ogm_aggr_packet whereas the buff_pos variable uses the s16 type. This could lead to an out-of-bound read.
--- net/batman-adv/bat_iv_ogm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/bat_iv_ogm.c +1 -1
@@ -335,7 +335,7 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,struct batadv_priv *bat_priv =netdev_priv (hard_iface->mesh_iface);const char *fwd_str;u8 packet_num; -s16 buff_pos; +int buff_pos;struct batadv_ogm_packet *batadv_ogm_packet;struct sk_buff *skb;u8 *packet_pos;
Signature · 1 line
2.47.3
Re: [PATCH net 1/8] batman-adv: fix integer overflow on buff_pos
This series was applied to netdev/net.git (main) by Sven Eckelmann <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Sven Eckelmann <[email protected]>:
Quoted 8 lines · On Fri, 8 May 2026 17:43:07 +0200 you wrote:
From: Lyes Bourennani <[email protected]>
Fixing an integer overflow present in
batadv_iv_ogm_send_to_if. The size check is done using the int type inbatadv_iv_ogm_aggr_packetwhereas thebuff_posvariable uses the s16 type. This could lead to an out-of-bound read.[...]
Here is the summary with links:
- [net,1/8] batman-adv: fix integer overflow on buff_pos
https://git.kernel.org/netdev/net/c/0799e5943611 - [net,2/8] batman-adv: reject new tp_meter sessions during teardown https://git.kernel.org/netdev/net/c/324354359242 - [net,3/8] batman-adv: stop tp_meter sessions during mesh teardown https://git.kernel.org/netdev/net/c/3d3cf6a7314a - [net,4/8] batman-adv: stop caching unowned originator pointers in BAT IV https://git.kernel.org/netdev/net/c/f03e85835329 - [net,5/8] batman-adv: tp_meter: fix tp_num leak on kmalloc failure https://git.kernel.org/netdev/net/c/ce425dd05d0f - [net,6/8] batman-adv: bla: prevent use-after-free when deleting claims https://git.kernel.org/netdev/net/c/4ae1709a3140 - [net,7/8] batman-adv: bla: only purge non-released claims https://git.kernel.org/netdev/net/c/cf6b60401159 - [net,8/8] batman-adv: bla: put backbone reference on failed claim hash insert https://git.kernel.org/netdev/net/c/ba9d20ee9076
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Simon Wunderlich
maintainerPATCH 2/8 batman-adv: reject new tp_meter sessions during teardown
In reply to Simon WunderlichFrom: Jiexun Wang <[email protected]>
Prevent tp_meter from starting new sender or receiver sessions after mesh_state has left BATADV_MESH_ACTIVE.
--- net/batman-adv/tp_meter.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
net/batman-adv/tp_meter.c +16 -1
@@ -947,6 +947,13 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst,/* look for an already existing test towards this node */ spin_lock_bh (&bat_priv->tp_list_lock); +if (atomic_read (&bat_priv->mesh_state) !=BATADV_MESH_ACTIVE ) { +spin_unlock_bh (&bat_priv->tp_list_lock); +batadv_tp_batctl_error_notify (BATADV_TP_REASON_DST_UNREACHABLE , + dst, bat_priv, session_cookie); +return ; + } + tp_vars =batadv_tp_list_find (bat_priv, dst);if (tp_vars) {spin_unlock_bh (&bat_priv->tp_list_lock);
@@ -1329,9 +1336,12 @@ static struct batadv_tp_vars * batadv_tp_init_recv(struct batadv_priv *bat_priv, const struct batadv_icmp_tp_packet *icmp) { - struct batadv_tp_vars *tp_vars; + struct batadv_tp_vars *tp_vars = NULL;spin_lock_bh (&bat_priv->tp_list_lock); +if (atomic_read (&bat_priv->mesh_state) !=BATADV_MESH_ACTIVE ) + goto out_unlock; + tp_vars =batadv_tp_list_find_session (bat_priv, icmp->orig, icmp->session);if (tp_vars)
@@ -1464,6 +1474,9 @@ void batadv_tp_meter_recv(struct batadv_priv *bat_priv, struct sk_buff *skb) {struct batadv_icmp_tp_packet *icmp; +if (atomic_read (&bat_priv->mesh_state) !=BATADV_MESH_ACTIVE ) + goto out; + icmp = (struct batadv_icmp_tp_packet *)skb->data;switch (icmp->subtype) {
@@ -1478,6 +1491,8 @@ void batadv_tp_meter_recv(struct batadv_priv *bat_priv, struct sk_buff *skb)"Received unknown TP Metric packet type %u\n" , icmp->subtype); } + +out:consume_skb (skb); }
Signature · 1 line
2.47.3
Simon Wunderlich
maintainerPATCH 3/8 batman-adv: stop tp_meter sessions during mesh teardown
In reply to Simon WunderlichFrom: Jiexun Wang <[email protected]>
TP meter sessions remain linked on bat_priv->tp_list after the netlink request has already finished. When the mesh interface is removed, batadv_mesh_free() currently tears down the mesh without first draining these sessions.
A running sender thread or a late incoming tp_meter packet can then keep processing against a mesh instance which is already shutting down. Synchronize tp_meter with the mesh lifetime by stopping all active sessions from batadv_mesh_free() and waiting for sender threads to exit before teardown continues.
--- net/batman-adv/main.c | 1 + net/batman-adv/tp_meter.c | 94 +++++++++++++++++++++++++++++++-------- net/batman-adv/tp_meter.h | 1 + net/batman-adv/types.h | 4 ++ 4 files changed, 82 insertions(+), 18 deletions(-)
net/batman-adv/main.c +1 -0
@@ -249,6 +249,7 @@ void batadv_mesh_free(struct net_device *mesh_iface)atomic_set (&bat_priv->mesh_state,BATADV_MESH_DEACTIVATING );batadv_purge_outstanding_packets (bat_priv,NULL ); +batadv_tp_stop_all (bat_priv);batadv_gw_node_free (bat_priv);
net/batman-adv/tp_meter.c +76 -18
145 lines not on this page · raw message
net/batman-adv/tp_meter.h +1 -0
@@ -17,6 +17,7 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst, u32 test_length, u32 *cookie);void batadv_tp_stop (struct batadv_priv *bat_priv,const u8 *dst,u8 return_value); +void batadv_tp_stop_all (struct batadv_priv *bat_priv);void batadv_tp_meter_recv (struct batadv_priv *bat_priv,struct sk_buff *skb);#endif /* _NET_BATMAN_ADV_TP_METER_H_ */
net/batman-adv/types.h +4 -0
@@ -14,6 +14,7 @@#include <linux/average.h> #include <linux/bitops.h> #include <linux/compiler.h> +#include <linux/completion.h> #include <linux/if.h> #include <linux/if_ether.h> #include <linux/kref.h>
@@ -1328,6 +1329,9 @@ struct batadv_tp_vars {/** @finish_work: work item for the finishing procedure */ struct delayed_work finish_work; +/** @finished: completion signaled when a sender thread exits */ +struct completion finished; +/** @test_length: test length in milliseconds */ u32 test_length;
Signature · 1 line
2.47.3
Sven Eckelmann
maintainerRe: [PATCH net 3/8] batman-adv: stop tp_meter sessions during mesh teardown
Quoted 7 lines · On Friday, 8 May 2026 17:43:09 CEST Simon Wunderlich wrote:
From: Jiexun Wang <[email protected]>
TP meter sessions remain linked on
bat_priv->tp_listafter the netlink request has already finished. When the mesh interface is removed,batadv_mesh_free()currently tears down the mesh without first draining these sessions.
Quoted 5 lines
A running sender thread or a late incoming
tp_meterpacket can then keep processing against a mesh instance which is already shutting down. Synchronizetp_meterwith the mesh lifetime by stopping all active sessions frombatadv_mesh_free()and waiting for sender threads to exit before teardown continues.
Regarding the review under
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260508154314.12817-1-sw%40simonwunderlich.de
The fix for this existing problem is planned for the second net PR - splitted due to the amount of patches. Besides this split, was not included in this one because I am waiting for the author to submit the v2 with my change request (to also fix the second occurrence of the invalid atomic_dec_and_test):
https://patchwork.open-mesh.org/project/b.a.t.m.a.n./patch/df73e607bda0c84b22d64d80f8ac887190242baf.1778118303.git.rakukuip@gmail.com/
Regards,
Sven
Simon Wunderlich
maintainerPATCH 4/8 batman-adv: stop caching unowned originator pointers in BAT IV
In reply to Simon WunderlichFrom: Jiexun Wang <[email protected]>
BAT IV keeps the last-hop neighbor address in each neigh_node, but some paths also cache an originator pointer derived from a temporary lookup. That pointer is not owned by the neigh_node and may no longer refer to a live originator entry after purge handling runs.
Stop storing the auxiliary originator pointer in the BAT IV neighbor state. When BAT IV needs the neighbor originator data, resolve it from the stored neighbor address and drop the reference again after use.
--- net/batman-adv/bat_iv_ogm.c | 83 ++++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 24 deletions(-)
net/batman-adv/bat_iv_ogm.c +59 -24
@@ -173,19 +173,12 @@ batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const u8 *addr)static struct batadv_neigh_node *batadv_iv_ogm_neigh_new (struct batadv_hard_iface *hard_iface,const u8 *neigh_addr, -struct batadv_orig_node *orig_node, -struct batadv_orig_node *orig_neigh) +struct batadv_orig_node *orig_node) {struct batadv_neigh_node *neigh_node; neigh_node =batadv_neigh_node_get_or_create (orig_node, hard_iface, neigh_addr); -if (!neigh_node) - goto out; - - neigh_node->orig_node = orig_neigh; - -out:return neigh_node; }
@@ -906,6 +899,31 @@ static u8 batadv_iv_orig_ifinfo_sum(struct batadv_orig_node *orig_node,return sum; } +/** +* batadv_iv_ogm_neigh_ifinfo_sum() - Get bcast_own sum for a last-hop neighbor +* @bat_priv: the bat priv with all the mesh interface information +* @neigh_node: last-hop neighbor of an originator +* +* Return: Number of replied (rebroadcasted) OGMs for the originator currently +* announced by the neighbor. Returns 0 if the neighbor's originator entry is +* not available anymore. +*/ +static u8 batadv_iv_ogm_neigh_ifinfo_sum (struct batadv_priv *bat_priv, +const struct batadv_neigh_node *neigh_node) +{ +struct batadv_orig_node *orig_neigh; +u8 sum; + + orig_neigh =batadv_orig_hash_find (bat_priv, neigh_node->addr); +if (!orig_neigh) +return 0 ; + + sum =batadv_iv_orig_ifinfo_sum (orig_neigh, neigh_node->if_incoming); +batadv_orig_node_put (orig_neigh); + +return sum; +} +/** * batadv_iv_ogm_orig_update() - use OGM to update corresponding data in an * originator
@@ -975,17 +993,9 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv, }if (!neigh_node) { -struct batadv_orig_node *orig_tmp; - - orig_tmp =batadv_iv_ogm_orig_get (bat_priv, ethhdr->h_source); -if (!orig_tmp) - goto unlock; - neigh_node =batadv_iv_ogm_neigh_new (if_incoming, ethhdr->h_source, - orig_node, orig_tmp); - -batadv_orig_node_put (orig_tmp); + orig_node);if (!neigh_node) goto unlock; }else {
@@ -1037,10 +1047,9 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,*/ if (router_ifinfo && neigh_ifinfo->bat_iv.tq_avg == router_ifinfo->bat_iv.tq_avg) { - sum_orig =batadv_iv_orig_ifinfo_sum (router->orig_node, - router->if_incoming); - sum_neigh =batadv_iv_orig_ifinfo_sum (neigh_node->orig_node, - neigh_node->if_incoming); + sum_orig =batadv_iv_ogm_neigh_ifinfo_sum (bat_priv, router); + sum_neigh =batadv_iv_ogm_neigh_ifinfo_sum (bat_priv, + neigh_node);if (sum_orig >= sum_neigh) goto out; }
@@ -1106,7 +1115,6 @@ static bool batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node,if (!neigh_node) neigh_node =batadv_iv_ogm_neigh_new (if_incoming, orig_neigh_node->orig, - orig_neigh_node, orig_neigh_node);if (!neigh_node)
@@ -1302,6 +1310,32 @@ batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,return ret; } +/** +* batadv_orig_to_direct_router() - get direct next hop neighbor to an orig address +* @bat_priv: the bat priv with all the mesh interface information +* @orig_addr: the originator MAC address to search the best next hop router for +* @if_outgoing: the interface where the OGM should be sent to +* +* Return: A neighbor node which is the best router towards the given originator +* address. Bonding candidates are ignored. +*/ +static struct batadv_neigh_node * +batadv_orig_to_direct_router (struct batadv_priv *bat_priv,u8 *orig_addr, +struct batadv_hard_iface *if_outgoing) +{ +struct batadv_neigh_node *neigh_node; +struct batadv_orig_node *orig_node; + + orig_node =batadv_orig_hash_find (bat_priv, orig_addr); +if (!orig_node) +return NULL ; + + neigh_node =batadv_orig_router_get (orig_node, if_outgoing); +batadv_orig_node_put (orig_node); + +return neigh_node; +} +/** * batadv_iv_ogm_process_per_outif() - process a batman iv OGM for an outgoing * interface
@@ -1372,8 +1406,9 @@ batadv_iv_ogm_process_per_outif(const struct sk_buff *skb, int ogm_offset, router =batadv_orig_router_get (orig_node, if_outgoing);if (router) { - router_router =batadv_orig_router_get (router->orig_node, - if_outgoing); + router_router =batadv_orig_to_direct_router (bat_priv, + router->addr, + if_outgoing); router_ifinfo =batadv_neigh_ifinfo_get (router, if_outgoing); }
Signature · 1 line
2.47.3
Simon Wunderlich
maintainerPATCH 5/8 batman-adv: tp_meter: fix tp_num leak on kmalloc failure
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
When batadv_tp_start() or batadv_tp_init_recv() fail to allocate a new tp_vars object, the previously incremented bat_priv->tp_num counter is never decremented. This causes tp_num to drift upward on each allocation failure. Since only BATADV_TP_MAX_NUM sessions can be started and the count is never reduced for these failed allocations, it causes to an exhaustion of throughput meter sessions. In worst case, no new throughput meter session can be started until the mesh interface is removed.
The error handling must decrement tp_num releasing the lock and aborting the creation of an throughput meter session
--- net/batman-adv/tp_meter.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/batman-adv/tp_meter.c +4 -1
@@ -994,6 +994,7 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst, tp_vars =kmalloc_obj (*tp_vars,GFP_ATOMIC );if (!tp_vars) { +atomic_dec (&bat_priv->tp_num);spin_unlock_bh (&bat_priv->tp_list_lock); batadv_dbg(BATADV_DBG_TP_METER, bat_priv, "Meter: %s cannot allocate list elements\n",
@@ -1366,8 +1367,10 @@ batadv_tp_init_recv(struct batadv_priv *bat_priv, } tp_vars =kmalloc_obj (*tp_vars,GFP_ATOMIC ); -if (!tp_vars) +if (!tp_vars) { +atomic_dec (&bat_priv->tp_num); goto out_unlock; + }ether_addr_copy (tp_vars->other_end, icmp->orig); tp_vars->role =BATADV_TP_RECEIVER ;
Signature · 1 line
2.47.3
Simon Wunderlich
maintainerPATCH 6/8 batman-adv: bla: prevent use-after-free when deleting claims
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
When batadv_bla_del_backbone_claims() removes all claims for a backbone, it does this by dropping the link entry in the hash list. This list entry itself was one of the references which need to be dropped at the same time via batadv_claim_put().
But the batadv_claim_put() must not be done before the last access to the claim object in this function. Otherwise the claim might be freed already by the batadv_claim_release() function before the list entry was dropped.
--- net/batman-adv/bridge_loop_avoidance.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/bridge_loop_avoidance.c +1 -1
@@ -318,8 +318,8 @@ batadv_bla_del_backbone_claims(struct batadv_bla_backbone_gw *backbone_gw)if (claim->backbone_gw != backbone_gw)continue ; -batadv_claim_put (claim);hlist_del_rcu (&claim->hash_entry); +batadv_claim_put (claim); }spin_unlock_bh (list_lock); }
Signature · 1 line
2.47.3
Simon Wunderlich
maintainerPATCH 7/8 batman-adv: bla: only purge non-released claims
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
When batadv_bla_purge_claims() goes through the list of claims, it is only traversing the hash list with an rcu_read_lock(). Due to a potential parallel batadv_claim_put(), it can happen that it encounters a claim which was actually in the process of being released+freed by batadv_claim_release(). In this case, backbone_gw is set to NULL before the delayed RCU kfree is started. Calling batadv_bla_claim_get_backbone_gw() is then no longer allowed because it would cause a NULL-ptr derefence.
To avoid this, only claims with a valid reference counter must be purged. All others are already taken care of.
--- net/batman-adv/bridge_loop_avoidance.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/batman-adv/bridge_loop_avoidance.c +8 -0
@@ -1288,6 +1288,13 @@ static void batadv_bla_purge_claims(struct batadv_priv *bat_priv,rcu_read_lock ();hlist_for_each_entry_rcu (claim, head, hash_entry) { +/* only purge claims not currently in the process of being released. +* Such claims could otherwise have a NULL-ptr backbone_gw set because +* they already went through batadv_claim_release() +*/ +if (!kref_get_unless_zero (&claim->refcount)) +continue ; + backbone_gw =batadv_bla_claim_get_backbone_gw (claim);if (now) goto purge_now;
@@ -1313,6 +1320,7 @@ static void batadv_bla_purge_claims(struct batadv_priv *bat_priv, claim->addr, claim->vid); skip:batadv_backbone_gw_put (backbone_gw); +batadv_claim_put (claim); }rcu_read_unlock (); }
Signature · 1 line
2.47.3
Simon Wunderlich
maintainerPATCH 8/8 batman-adv: bla: put backbone reference on failed claim hash insert
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
When batadv_bla_add_claim() fails to insert a new claim into the hash, it leaked a reference to the backbone_gw for which the claim was intended. Call batadv_backbone_gw_put() on the error path to release the reference and avoid leaking the backbone_gw object.
--- net/batman-adv/bridge_loop_avoidance.c | 1 + 1 file changed, 1 insertion(+)
net/batman-adv/bridge_loop_avoidance.c +1 -0
@@ -723,6 +723,7 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,if (unlikely (hash_added !=0 )) {/* only local changes happened. */ +batadv_backbone_gw_put (backbone_gw);kfree (claim);return ; }
Signature · 1 line
2.47.3