Commit 1f02a09c authored by Maor Gottlieb's avatar Maor Gottlieb Committed by Doug Ledford

IB/mlx4: Add validation to flow specifications parsing

Add validation check that all set fields in flow specification
are supported by vendor.
Signed-off-by: default avatarMaor Gottlieb <maorg@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leon@kernel.org>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent cc0e5d42
...@@ -1361,6 +1361,19 @@ struct mlx4_ib_steering { ...@@ -1361,6 +1361,19 @@ struct mlx4_ib_steering {
union ib_gid gid; union ib_gid gid;
}; };
#define LAST_ETH_FIELD vlan_tag
#define LAST_IB_FIELD sl
#define LAST_IPV4_FIELD dst_ip
#define LAST_TCP_UDP_FIELD src_port
/* Field is the last supported field */
#define FIELDS_NOT_SUPPORTED(filter, field)\
memchr_inv((void *)&filter.field +\
sizeof(filter.field), 0,\
sizeof(filter) -\
offsetof(typeof(filter), field) -\
sizeof(filter.field))
static int parse_flow_attr(struct mlx4_dev *dev, static int parse_flow_attr(struct mlx4_dev *dev,
u32 qp_num, u32 qp_num,
union ib_flow_spec *ib_spec, union ib_flow_spec *ib_spec,
...@@ -1370,6 +1383,9 @@ static int parse_flow_attr(struct mlx4_dev *dev, ...@@ -1370,6 +1383,9 @@ static int parse_flow_attr(struct mlx4_dev *dev,
switch (ib_spec->type) { switch (ib_spec->type) {
case IB_FLOW_SPEC_ETH: case IB_FLOW_SPEC_ETH:
if (FIELDS_NOT_SUPPORTED(ib_spec->eth.mask, LAST_ETH_FIELD))
return -ENOTSUPP;
type = MLX4_NET_TRANS_RULE_ID_ETH; type = MLX4_NET_TRANS_RULE_ID_ETH;
memcpy(mlx4_spec->eth.dst_mac, ib_spec->eth.val.dst_mac, memcpy(mlx4_spec->eth.dst_mac, ib_spec->eth.val.dst_mac,
ETH_ALEN); ETH_ALEN);
...@@ -1379,6 +1395,9 @@ static int parse_flow_attr(struct mlx4_dev *dev, ...@@ -1379,6 +1395,9 @@ static int parse_flow_attr(struct mlx4_dev *dev,
mlx4_spec->eth.vlan_tag_msk = ib_spec->eth.mask.vlan_tag; mlx4_spec->eth.vlan_tag_msk = ib_spec->eth.mask.vlan_tag;
break; break;
case IB_FLOW_SPEC_IB: case IB_FLOW_SPEC_IB:
if (FIELDS_NOT_SUPPORTED(ib_spec->ib.mask, LAST_IB_FIELD))
return -ENOTSUPP;
type = MLX4_NET_TRANS_RULE_ID_IB; type = MLX4_NET_TRANS_RULE_ID_IB;
mlx4_spec->ib.l3_qpn = mlx4_spec->ib.l3_qpn =
cpu_to_be32(qp_num); cpu_to_be32(qp_num);
...@@ -1388,6 +1407,9 @@ static int parse_flow_attr(struct mlx4_dev *dev, ...@@ -1388,6 +1407,9 @@ static int parse_flow_attr(struct mlx4_dev *dev,
case IB_FLOW_SPEC_IPV4: case IB_FLOW_SPEC_IPV4:
if (FIELDS_NOT_SUPPORTED(ib_spec->ipv4.mask, LAST_IPV4_FIELD))
return -ENOTSUPP;
type = MLX4_NET_TRANS_RULE_ID_IPV4; type = MLX4_NET_TRANS_RULE_ID_IPV4;
mlx4_spec->ipv4.src_ip = ib_spec->ipv4.val.src_ip; mlx4_spec->ipv4.src_ip = ib_spec->ipv4.val.src_ip;
mlx4_spec->ipv4.src_ip_msk = ib_spec->ipv4.mask.src_ip; mlx4_spec->ipv4.src_ip_msk = ib_spec->ipv4.mask.src_ip;
...@@ -1397,6 +1419,9 @@ static int parse_flow_attr(struct mlx4_dev *dev, ...@@ -1397,6 +1419,9 @@ static int parse_flow_attr(struct mlx4_dev *dev,
case IB_FLOW_SPEC_TCP: case IB_FLOW_SPEC_TCP:
case IB_FLOW_SPEC_UDP: case IB_FLOW_SPEC_UDP:
if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask, LAST_TCP_UDP_FIELD))
return -ENOTSUPP;
type = ib_spec->type == IB_FLOW_SPEC_TCP ? type = ib_spec->type == IB_FLOW_SPEC_TCP ?
MLX4_NET_TRANS_RULE_ID_TCP : MLX4_NET_TRANS_RULE_ID_TCP :
MLX4_NET_TRANS_RULE_ID_UDP; MLX4_NET_TRANS_RULE_ID_UDP;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment