From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id BE5ED1B71B for ; Wed, 9 May 2018 17:29:16 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from shahafs@mellanox.com) with ESMTPS (AES256-SHA encrypted); 9 May 2018 18:06:13 +0300 Received: from unicorn01.mtl.labs.mlnx. (unicorn01.mtl.labs.mlnx [10.7.12.62]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w49F4Srb008373; Wed, 9 May 2018 18:04:30 +0300 From: Shahaf Shuler To: bluca@debian.org Cc: stable@dpdk.org, nelio.laranjeiro@6wind.com, adrien.mazarguil@6wind.com, yskoh@mellanox.com Date: Wed, 9 May 2018 18:04:12 +0300 Message-Id: <7c41640b3d1b24cf5e849b1746d6539fb8e95e9e.1525878119.git.shahafs@mellanox.com> X-Mailer: git-send-email 2.12.0 MIME-Version: 1.0 In-Reply-To: References: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] [PATCH v2 20/20] net/mlx5: fix flow validation X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 May 2018 15:29:17 -0000 From: Nélio Laranjeiro [ upstream commit 6b36814e93f7b55f55dae127b6d6def91ded5179 ] Item spec and last are wrongly compared to the NIC capability causing a validation failure when the mask is null. This validation function should only verify the user is not configuring unsupported matching fields. Fixes: 2097d0d1e2cc ("net/mlx5: support basic flow items and actions") Cc: stable@dpdk.org Signed-off-by: Nelio Laranjeiro --- drivers/net/mlx5/mlx5_flow.c | 77 +++++++++++++-------------------------- 1 file changed, 25 insertions(+), 52 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index c03a37506d..b40c3cac77 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -459,7 +459,7 @@ struct ibv_spec_header { }; /** - * Check support for a given item. + * Check item is fully supported by the NIC matching capability. * * @param item[in] * Item specification. @@ -476,60 +476,33 @@ static int mlx5_flow_item_validate(const struct rte_flow_item *item, const uint8_t *mask, unsigned int size) { - if (!item->spec && (item->mask || item->last)) { - rte_errno = EINVAL; - return -rte_errno; - } - if (item->spec && !item->mask) { - unsigned int i; - const uint8_t *spec = item->spec; - - for (i = 0; i < size; ++i) - if ((spec[i] | mask[i]) != mask[i]) { - rte_errno = EINVAL; - return -rte_errno; - } - } - if (item->last && !item->mask) { - unsigned int i; - const uint8_t *spec = item->last; - - for (i = 0; i < size; ++i) - if ((spec[i] | mask[i]) != mask[i]) { - rte_errno = EINVAL; - return -rte_errno; - } - } - if (item->mask) { - unsigned int i; - const uint8_t *spec = item->spec; - - for (i = 0; i < size; ++i) - if ((spec[i] | mask[i]) != mask[i]) { - rte_errno = EINVAL; - return -rte_errno; - } - } - if (item->spec && item->last) { - uint8_t spec[size]; - uint8_t last[size]; - const uint8_t *apply = mask; - unsigned int i; - int ret; + unsigned int i; + const uint8_t *spec = item->spec; + const uint8_t *last = item->last; + const uint8_t *m = item->mask ? item->mask : mask; - if (item->mask) - apply = item->mask; - for (i = 0; i < size; ++i) { - spec[i] = ((const uint8_t *)item->spec)[i] & apply[i]; - last[i] = ((const uint8_t *)item->last)[i] & apply[i]; - } - ret = memcmp(spec, last, size); - if (ret != 0) { - rte_errno = EINVAL; - return -rte_errno; - } + if (!spec && (item->mask || last)) + goto error; + if (!spec) + return 0; + /* + * Single-pass check to make sure that: + * - item->mask is supported, no bits are set outside mask. + * - Both masked item->spec and item->last are equal (no range + * supported). + */ + for (i = 0; i < size; i++) { + if (!m[i]) + continue; + if ((m[i] | mask[i]) != mask[i]) + goto error; + if (last && ((spec[i] & m[i]) != (last[i] & m[i]))) + goto error; } return 0; +error: + rte_errno = ENOTSUP; + return -rte_errno; } /** -- 2.12.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 7AAD21B6E0 for ; Wed, 9 May 2018 17:29:34 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from shahafs@mellanox.com) with ESMTPS (AES256-SHA encrypted); 9 May 2018 18:19:34 +0300 Received: from unicorn01.mtl.labs.mlnx. (unicorn01.mtl.labs.mlnx [10.7.12.62]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w49FHoVR003207; Wed, 9 May 2018 18:17:51 +0300 From: Shahaf Shuler To: shahafs@mellanox.com Cc: yskoh@mellanox.com, =?UTF-8?q?N=C3=A9lio=20Laranjeiro?= , stable@dpdk.org Date: Wed, 9 May 2018 18:17:48 +0300 Message-Id: <7c41640b3d1b24cf5e849b1746d6539fb8e95e9e.1525878119.git.shahafs@mellanox.com> X-Mailer: git-send-email 2.12.0 MIME-Version: 1.0 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] [PATCH v2 20/20] net/mlx5: fix flow validation X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 May 2018 15:29:34 -0000 Message-ID: <20180509151748.hdugBA7m3EaN1QdRwynIH63Lr2NgenhW6vqN0UaP7Po@z> From: Nélio Laranjeiro [ upstream commit 6b36814e93f7b55f55dae127b6d6def91ded5179 ] Item spec and last are wrongly compared to the NIC capability causing a validation failure when the mask is null. This validation function should only verify the user is not configuring unsupported matching fields. Fixes: 2097d0d1e2cc ("net/mlx5: support basic flow items and actions") Cc: stable@dpdk.org Signed-off-by: Nelio Laranjeiro --- drivers/net/mlx5/mlx5_flow.c | 77 +++++++++++++-------------------------- 1 file changed, 25 insertions(+), 52 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index c03a37506d..b40c3cac77 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -459,7 +459,7 @@ struct ibv_spec_header { }; /** - * Check support for a given item. + * Check item is fully supported by the NIC matching capability. * * @param item[in] * Item specification. @@ -476,60 +476,33 @@ static int mlx5_flow_item_validate(const struct rte_flow_item *item, const uint8_t *mask, unsigned int size) { - if (!item->spec && (item->mask || item->last)) { - rte_errno = EINVAL; - return -rte_errno; - } - if (item->spec && !item->mask) { - unsigned int i; - const uint8_t *spec = item->spec; - - for (i = 0; i < size; ++i) - if ((spec[i] | mask[i]) != mask[i]) { - rte_errno = EINVAL; - return -rte_errno; - } - } - if (item->last && !item->mask) { - unsigned int i; - const uint8_t *spec = item->last; - - for (i = 0; i < size; ++i) - if ((spec[i] | mask[i]) != mask[i]) { - rte_errno = EINVAL; - return -rte_errno; - } - } - if (item->mask) { - unsigned int i; - const uint8_t *spec = item->spec; - - for (i = 0; i < size; ++i) - if ((spec[i] | mask[i]) != mask[i]) { - rte_errno = EINVAL; - return -rte_errno; - } - } - if (item->spec && item->last) { - uint8_t spec[size]; - uint8_t last[size]; - const uint8_t *apply = mask; - unsigned int i; - int ret; + unsigned int i; + const uint8_t *spec = item->spec; + const uint8_t *last = item->last; + const uint8_t *m = item->mask ? item->mask : mask; - if (item->mask) - apply = item->mask; - for (i = 0; i < size; ++i) { - spec[i] = ((const uint8_t *)item->spec)[i] & apply[i]; - last[i] = ((const uint8_t *)item->last)[i] & apply[i]; - } - ret = memcmp(spec, last, size); - if (ret != 0) { - rte_errno = EINVAL; - return -rte_errno; - } + if (!spec && (item->mask || last)) + goto error; + if (!spec) + return 0; + /* + * Single-pass check to make sure that: + * - item->mask is supported, no bits are set outside mask. + * - Both masked item->spec and item->last are equal (no range + * supported). + */ + for (i = 0; i < size; i++) { + if (!m[i]) + continue; + if ((m[i] | mask[i]) != mask[i]) + goto error; + if (last && ((spec[i] & m[i]) != (last[i] & m[i]))) + goto error; } return 0; +error: + rte_errno = ENOTSUP; + return -rte_errno; } /** -- 2.12.0