When a batadv_hard_iface is disabled, its mesh_iface pointer is set to
NULL. However, batadv_v_ogm_send_meshif() may still dispatch OGMs via
batadv_v_ogm_queue_on_if() for interfaces that have since lost their
mesh_iface association. This results in a NULL pointer dereference when
batadv_v_ogm_queue_on_if() unconditionally calls netdev_priv() on the
now NULL hard_iface->mesh_iface to retrieve the batadv_priv.

It is necessary to ensure that the batadv_v_ogm_queue_on_if() checks that
it is using the same mesh_iface for which batadv_v_ogm_send_meshif() was
called.

Cc: [email protected]
Fixes: 0da0035942d4 ("batman-adv: OGMv2 - add basic infrastructure")
Reported-by: Yuan Tan <[email protected]>
Reported-by: Yifan Wu <[email protected]>
Reported-by: Juefei Pu <[email protected]>
Reported-by: Xin Liu <[email protected]>
Signed-off-by: Sven Eckelmann <[email protected]>
---
 net/batman-adv/bat_v_ogm.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/net/batman-adv/bat_v_ogm.c b/net/batman-adv/bat_v_ogm.c
index 9914346a..99a2ce9f 100644
--- a/net/batman-adv/bat_v_ogm.c
+++ b/net/batman-adv/bat_v_ogm.c
@@ -232,13 +232,16 @@ static void batadv_v_ogm_aggr_send(struct 
batadv_hard_iface *hard_iface)
 
 /**
  * batadv_v_ogm_queue_on_if() - queue a batman ogm on a given interface
+ * @bat_priv: the bat priv with all the mesh interface information
  * @skb: the OGM to queue
  * @hard_iface: the interface to queue the OGM on
  */
-static void batadv_v_ogm_queue_on_if(struct sk_buff *skb,
+static void batadv_v_ogm_queue_on_if(struct batadv_priv *bat_priv,
+                                    struct sk_buff *skb,
                                     struct batadv_hard_iface *hard_iface)
 {
-       struct batadv_priv *bat_priv = netdev_priv(hard_iface->mesh_iface);
+       if (hard_iface->mesh_iface != bat_priv->mesh_iface)
+               return;
 
        if (!atomic_read(&bat_priv->aggregated_ogms)) {
                batadv_v_ogm_send_to_if(skb, hard_iface);
@@ -344,7 +347,7 @@ static void batadv_v_ogm_send_meshif(struct batadv_priv 
*bat_priv)
                        break;
                }
 
-               batadv_v_ogm_queue_on_if(skb_tmp, hard_iface);
+               batadv_v_ogm_queue_on_if(bat_priv, skb_tmp, hard_iface);
                batadv_hardif_put(hard_iface);
        }
        rcu_read_unlock();
@@ -579,7 +582,7 @@ static void batadv_v_ogm_forward(struct batadv_priv 
*bat_priv,
                   if_outgoing->net_dev->name, ntohl(ogm_forward->throughput),
                   ogm_forward->ttl, if_incoming->net_dev->name);
 
-       batadv_v_ogm_queue_on_if(skb, if_outgoing);
+       batadv_v_ogm_queue_on_if(bat_priv, skb, if_outgoing);
 
 out:
        batadv_orig_ifinfo_put(orig_ifinfo);

-- 
2.47.3

Reply via email to