mlxsw: core: Increase scope of RCU read-side critical section
authorIdo Schimmel <idosch@mellanox.com>
Wed, 29 Jul 2020 09:26:45 +0000 (12:26 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 21 Aug 2020 09:01:50 +0000 (11:01 +0200)
[ Upstream commit 7d8e8f3433dc8d1dc87c1aabe73a154978fb4c4d ]

The lifetime of the Rx listener item ('rxl_item') is managed using RCU,
but is dereferenced outside of RCU read-side critical section, which can
lead to a use-after-free.

Fix this by increasing the scope of the RCU read-side critical section.

Fixes: 93c1edb27f9e ("mlxsw: Introduce Mellanox switch driver core")
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/mellanox/mlxsw/core.c

index aa33d58b9f81ca9812a59cf8cc48a3a44322975a..6ebe88deab62acac18ac82bcaadf2e92dda7c04a 100644 (file)
@@ -1584,9 +1584,10 @@ void mlxsw_core_skb_receive(struct mlxsw_core *mlxsw_core, struct sk_buff *skb,
                        break;
                }
        }
-       rcu_read_unlock();
-       if (!found)
+       if (!found) {
+               rcu_read_unlock();
                goto drop;
+       }
 
        pcpu_stats = this_cpu_ptr(mlxsw_core->pcpu_stats);
        u64_stats_update_begin(&pcpu_stats->syncp);
@@ -1597,6 +1598,7 @@ void mlxsw_core_skb_receive(struct mlxsw_core *mlxsw_core, struct sk_buff *skb,
        u64_stats_update_end(&pcpu_stats->syncp);
 
        rxl->func(skb, local_port, rxl_item->priv);
+       rcu_read_unlock();
        return;
 
 drop: