VXLAN and GENEVE flows truncate the key and the mask of enc_key_id to a 24 bit VNI. An exact key above bit 23 already selects the wrong VNI. Flower is about to accept partial masks. A mask that only covers bits above 23 would then match any VNI. Refuse a key that no VNI can match. GRE keeps its 32 bit key. Found by an AI code review agent while auditing the users of enc_key_id. Confirmed by code inspection. The wrong match was not triggered. Tested on ConnectX-7 with firmware 28.48.1000 in switchdev mode on VXLAN, GENEVE and gretap devices. Fixes: bbd00f7e2349 ("net/mlx5e: Add TC tunnel release action for SRIOV offloads") Fixes: 9272e3df3023 ("net/mlx5e: Geneve, Add support for encap/decap flows offload") Signed-off-by: Alexandre Cassen --- drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h | 3 +++ .../net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c | 8 ++++++++ drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h index 6873c1201803..d7c778bbb2ef 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h @@ -13,6 +13,9 @@ #ifdef CONFIG_MLX5_ESWITCH +/* VXLAN and GENEVE match registers hold a 24 bit VNI */ +#define MLX5E_TC_TUN_N_VNI BIT(24) + enum { MLX5E_TC_TUNNEL_TYPE_UNKNOWN, MLX5E_TC_TUNNEL_TYPE_VXLAN, diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c index bf969212cc77..ee04fcdca6ff 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c @@ -141,6 +141,14 @@ static int mlx5e_tc_tun_parse_geneve_vni(struct mlx5e_priv *priv, if (!enc_keyid.mask->keyid) return 0; + if (be32_to_cpu(enc_keyid.key->keyid) >= MLX5E_TC_TUN_N_VNI) { + NL_SET_ERR_MSG_MOD(extack, + "Tunnel key does not fit the 24 bit VNI"); + netdev_warn(priv->netdev, + "Tunnel key does not fit the 24 bit VNI\n"); + return -EOPNOTSUPP; + } + if (!MLX5_CAP_ESW_FLOWTABLE_FDB(priv->mdev, ft_field_support.outer_geneve_vni)) { NL_SET_ERR_MSG_MOD(extack, "Matching on GENEVE VNI is not supported"); netdev_warn(priv->netdev, "Matching on GENEVE VNI is not supported\n"); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c index 467fbe43b89e..33911e72d20d 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c @@ -173,6 +173,14 @@ static int mlx5e_tc_tun_parse_vxlan(struct mlx5e_priv *priv, if (!enc_keyid.mask->keyid) return 0; + if (be32_to_cpu(enc_keyid.key->keyid) >= MLX5E_TC_TUN_N_VNI) { + NL_SET_ERR_MSG_MOD(extack, + "Tunnel key does not fit the 24 bit VNI"); + netdev_warn(priv->netdev, + "Tunnel key does not fit the 24 bit VNI\n"); + return -EOPNOTSUPP; + } + if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_OPTS)) { int err; -- 2.43.0