Skip to contentSkip to conversation

batman-adv: Fix double neigh_node_put in batadv_v_ogm_route_update

PATCH Applied Sven Eckelmann 4 participants 7 messages May 6, 2016 – May 7, 2016 Batman advanced

lore
Share & tools
lore

Sven Eckelmann

author maintainer
#0 lore raw

PATCH 1/1 batman-adv: Fix double neigh_node_put in batadv_v_ogm_route_update

The router is put down twice when it was non-NULL and either orig_ifinfo is NULL afterwards or batman-adv receives a packet with the same sequence number. This will end up in a use-after-free when the batadv_neigh_node is removed because the reference counter ended up too early at 0.

Fixes 667996ebeab4 ("batman-adv: OGMv2 - implement originators logic")

---
It looks like this bug was solved in next/master by refactoring in 30c96bc7870f ("batman-adv: move and restructure batadv_v_ogm_forward")

only compile tested. Please add so many reported by as you want - just don't know it it is *the* bug and who actually reported it.

---
 net/batman-adv/bat_v_ogm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/batman-adv/bat_v_ogm.c +3 -1
index d9bcbe6..91df28a 100644
@@ -529,8 +529,10 @@ static void batadv_v_ogm_route_update(struct batadv_priv *bat_priv,
 		goto out;
 	}
 
-	if (router)
+	if (router) {
 		batadv_neigh_node_put(router);
+		router = NULL;
+	}
 
 	/* Update routes, and check if the OGM is from the best next hop */
 	batadv_v_ogm_orig_update(bat_priv, orig_node, neigh_node, ogm2,
Signature · 1 line
2.8.1
author maintainer
#1 lore raw
Quoted 7 lines · On Friday 06 May 2016 22:27:09 Sven Eckelmann wrote:

The router is put down twice when it was non-NULL and either orig_ifinfo is NULL afterwards or batman-adv receives a packet with the same sequence number. This will end up in a use-after-free when the batadv_neigh_node is removed because the reference counter ended up too early at 0.

Fixes 667996ebeab4 ("batman-adv: OGMv2 - implement originators logic")

[...]

There is a conflict with master. I hope that Antonio can share how it can be resolved when he submits following remaining fixes to David:

* batman-adv: Fix integer overflow in batadv_iv_ogm_calc_tq
* batman-adv: Avoid duplicate neigh_node additions
* batman-adv: make sure ELP/OGM orig MAC is updated on address change
* batman-adv: Fix unexpected free of bcast_own on add_if error
* batman-adv: Avoid nullptr derefence in batadv_v_neigh_is_sob
* batman-adv: Fix refcnt leak in batadv_v_neigh_*
* batman-adv: Fix double neigh_node_put in batadv_v_ogm_route_update

The solution for the merge conflict with master is:

net/batman-adv/bat_v_ogm.c +0 -7
@@ -510,17 +510,10 @@
                goto out;
        }
 
-<<<<<<<
        /* Mark the OGM to be considered for forwarding, and update routes
         * if needed.
         */
        forward = true;
-=======
-       if (router) {
-               batadv_neigh_node_put(router);
-               router = NULL;
-       }
->>>>>>>
 
        batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
                   "Searching and updating originator entry of received packet\n");
#2 lore raw
Quoted 33 lines · Sven Eckelmann
Quoted 7 lines · On Friday 06 May 2016 22:27:09 Sven Eckelmann wrote:

The router is put down twice when it was non-NULL and either orig_ifinfo is NULL afterwards or batman-adv receives a packet with the same sequence number. This will end up in a use-after-free when the batadv_neigh_node is removed because the reference counter ended up too early at 0.

Fixes 667996ebeab4 ("batman-adv: OGMv2 - implement originators logic")

[...]

There is a conflict with master. I hope that Antonio can share how it can be resolved when he submits following remaining fixes to David:

* batman-adv: Fix integer overflow in batadv_iv_ogm_calc_tq
* batman-adv: Avoid duplicate neigh_node additions
* batman-adv: make sure ELP/OGM orig MAC is updated on address change
* batman-adv: Fix unexpected free of bcast_own on add_if error
* batman-adv: Avoid nullptr derefence in batadv_v_neigh_is_sob
* batman-adv: Fix refcnt leak in batadv_v_neigh_*
* batman-adv: Fix double neigh_node_put in batadv_v_ogm_route_update

The solution for the merge conflict with master is:

net/batman-adv/bat_v_ogm.c +0 -1
@@ -510,17 +510,10 @@
                goto out;
        }
 
-<<<<<<<
        /* Mark the OGM to be considered for forwarding, and update routes
         * if needed.
         */

net/batman-adv/bat_v_ogm.c line 519

Quoted 10 lines
net/batman-adv/bat_v_ogm.c +0 -6
        forward = true;
-=======
-       if (router) {
-               batadv_neigh_node_put(router);
-               router = NULL;
-       }
->>>>>>>
 
        batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
                   "Searching and updating originator entry of received packet\n");

Thanks a lot for this.

Cheers,

Signature · 1 line
Antonio Quartulli
Tested-by on v1 1/1
#3 lore raw
In reply to Sven Eckelmann
Quoted 7 lines · Sven Eckelmann

The router is put down twice when it was non-NULL and either orig_ifinfo is NULL afterwards or batman-adv receives a packet with the same sequence number. This will end up in a use-after-free when the batadv_neigh_node is removed because the reference counter ended up too early at 0.

Fixes 667996ebeab4 ("batman-adv: OGMv2 - implement originators logic")

it fixes the crash reported in "Kernel panic by BATMAN_V @WBMv9" for me.

@Marek: can you also test this patch in your environment to see if you still see the crash?

Cheers,

Signature · 1 line
Antonio Quartulli
#4 lore raw
In reply to Sven Eckelmann
Quoted 11 lines · On Friday, May 06, 2016 22:27:09 Sven Eckelmann wrote:

The router is put down twice when it was non-NULL and either orig_ifinfo is NULL afterwards or batman-adv receives a packet with the same sequence number. This will end up in a use-after-free when the batadv_neigh_node is removed because the reference counter ended up too early at 0.

Fixes 667996ebeab4 ("batman-adv: OGMv2 - implement originators logic")

---
It looks like this bug was solved in next/master by refactoring in 30c96bc7870f ("batman-adv: move and restructure batadv_v_ogm_forward")

Quoted 5 lines

only compile tested. Please add so many reported by as you want - just don't know it it is *the* bug and who actually reported it.

---
 net/batman-adv/bat_v_ogm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Applied in revision fc3e79d.

Thanks,
Marek

#5 lore raw

[B.A.T.M.A.N.] no able to switch routing algo to V ?

Hello,

I just got openwrt 15.05.1 with batman-adv 2016.1 on 3 picostation HP, this time a selected before the build of openwrt batman V option, I can see it when it ask for available routing algo ,

root@OpenWrt:/etc/init.d# cat /sys/kernel/debug/batman_adv/routing_algos
Available routing algorithms:
 * BATMAN_IV
 * BATMAN_V

but when I do :

echo BATMAN_V > /sys/module/batman_adv/parameters/routing_algo

It does nothing, still on BATMAN_IV during session and on reboot ?

Best Regards,

Laurent

author maintainer
#6 lore raw

Re: [B.A.T.M.A.N.] no able to switch routing algo to V ?

Quoted 9 lines · On Saturday 07 May 2016 14:29:17 contact wrote:

I just got openwrt 15.05.1 with batman-adv 2016.1 on 3 picostation HP, this time a selected before the build of openwrt batman V option, I can see it when it ask for available routing algo ,

root@OpenWrt:/etc/init.d# cat /sys/kernel/debug/batman_adv/routing_algos
Available routing algorithms:
  * BATMAN_IV
  * BATMAN_V
Quoted 5 lines

but when I do :

echo BATMAN_V > /sys/module/batman_adv/parameters/routing_algo

It does nothing, still on BATMAN_IV during session and on reboot ?

Please don't hijack other (unrelated) threads,

Kind regards,
Sven