Commit c47ac6ae authored by Maor Gottlieb's avatar Maor Gottlieb Committed by Doug Ledford

IB/mlx5: 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 1f02a09c
...@@ -1436,6 +1436,20 @@ static bool outer_header_zero(u32 *match_criteria) ...@@ -1436,6 +1436,20 @@ static bool outer_header_zero(u32 *match_criteria)
size - 1); size - 1);
} }
#define LAST_ETH_FIELD vlan_tag
#define LAST_IB_FIELD sl
#define LAST_IPV4_FIELD dst_ip
#define LAST_IPV6_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(u32 *match_c, u32 *match_v, static int parse_flow_attr(u32 *match_c, u32 *match_v,
const union ib_flow_spec *ib_spec) const union ib_flow_spec *ib_spec)
{ {
...@@ -1445,8 +1459,8 @@ static int parse_flow_attr(u32 *match_c, u32 *match_v, ...@@ -1445,8 +1459,8 @@ static int parse_flow_attr(u32 *match_c, u32 *match_v,
outer_headers); outer_headers);
switch (ib_spec->type) { switch (ib_spec->type) {
case IB_FLOW_SPEC_ETH: case IB_FLOW_SPEC_ETH:
if (ib_spec->size != sizeof(ib_spec->eth)) if (FIELDS_NOT_SUPPORTED(ib_spec->eth.mask, LAST_ETH_FIELD))
return -EINVAL; return -ENOTSUPP;
ether_addr_copy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, outer_headers_c, ether_addr_copy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, outer_headers_c,
dmac_47_16), dmac_47_16),
...@@ -1486,8 +1500,8 @@ static int parse_flow_attr(u32 *match_c, u32 *match_v, ...@@ -1486,8 +1500,8 @@ static int parse_flow_attr(u32 *match_c, u32 *match_v,
ethertype, ntohs(ib_spec->eth.val.ether_type)); ethertype, ntohs(ib_spec->eth.val.ether_type));
break; break;
case IB_FLOW_SPEC_IPV4: case IB_FLOW_SPEC_IPV4:
if (ib_spec->size != sizeof(ib_spec->ipv4)) if (FIELDS_NOT_SUPPORTED(ib_spec->ipv4.mask, LAST_IPV4_FIELD))
return -EINVAL; return -ENOTSUPP;
MLX5_SET(fte_match_set_lyr_2_4, outer_headers_c, MLX5_SET(fte_match_set_lyr_2_4, outer_headers_c,
ethertype, 0xffff); ethertype, 0xffff);
...@@ -1512,8 +1526,8 @@ static int parse_flow_attr(u32 *match_c, u32 *match_v, ...@@ -1512,8 +1526,8 @@ static int parse_flow_attr(u32 *match_c, u32 *match_v,
sizeof(ib_spec->ipv4.val.dst_ip)); sizeof(ib_spec->ipv4.val.dst_ip));
break; break;
case IB_FLOW_SPEC_IPV6: case IB_FLOW_SPEC_IPV6:
if (ib_spec->size != sizeof(ib_spec->ipv6)) if (FIELDS_NOT_SUPPORTED(ib_spec->ipv6.mask, LAST_IPV6_FIELD))
return -EINVAL; return -ENOTSUPP;
MLX5_SET(fte_match_set_lyr_2_4, outer_headers_c, MLX5_SET(fte_match_set_lyr_2_4, outer_headers_c,
ethertype, 0xffff); ethertype, 0xffff);
...@@ -1538,8 +1552,9 @@ static int parse_flow_attr(u32 *match_c, u32 *match_v, ...@@ -1538,8 +1552,9 @@ static int parse_flow_attr(u32 *match_c, u32 *match_v,
sizeof(ib_spec->ipv6.val.dst_ip)); sizeof(ib_spec->ipv6.val.dst_ip));
break; break;
case IB_FLOW_SPEC_TCP: case IB_FLOW_SPEC_TCP:
if (ib_spec->size != sizeof(ib_spec->tcp_udp)) if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask,
return -EINVAL; LAST_TCP_UDP_FIELD))
return -ENOTSUPP;
MLX5_SET(fte_match_set_lyr_2_4, outer_headers_c, ip_protocol, MLX5_SET(fte_match_set_lyr_2_4, outer_headers_c, ip_protocol,
0xff); 0xff);
...@@ -1557,8 +1572,9 @@ static int parse_flow_attr(u32 *match_c, u32 *match_v, ...@@ -1557,8 +1572,9 @@ static int parse_flow_attr(u32 *match_c, u32 *match_v,
ntohs(ib_spec->tcp_udp.val.dst_port)); ntohs(ib_spec->tcp_udp.val.dst_port));
break; break;
case IB_FLOW_SPEC_UDP: case IB_FLOW_SPEC_UDP:
if (ib_spec->size != sizeof(ib_spec->tcp_udp)) if (FIELDS_NOT_SUPPORTED(ib_spec->tcp_udp.mask,
return -EINVAL; LAST_TCP_UDP_FIELD))
return -ENOTSUPP;
MLX5_SET(fte_match_set_lyr_2_4, outer_headers_c, ip_protocol, MLX5_SET(fte_match_set_lyr_2_4, outer_headers_c, ip_protocol,
0xff); 0xff);
......
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