Blame SOURCES/0001-Add-a-helper-function-to-verify-64-bit-comp-mask.patch

6698ac
From abb3bf03bcb543915852204b4fdaf6a88873b51a Mon Sep 17 00:00:00 2001
6698ac
From: Noa Osherovich <noaos@mellanox.com>
6698ac
Date: Wed, 22 Nov 2017 11:11:21 +0200
6698ac
Subject: [PATCH rdma-core 1/3] Add a helper function to verify 64 bit comp
6698ac
 mask
6698ac
6698ac
The common check for a mask is as follows:
6698ac
if (comp_mask & ~COMP_MASK_SUPPORTED_VALUES)
6698ac
	return EINVAL
6698ac
6698ac
This can cause an issue when using 64 bit mask if the supported variable
6698ac
is signed 32 bit: It will be bitwise inverted and then zeroed to 64
6698ac
bits. This way wrong bits in the mask that exceed 32 bits will not raise
6698ac
an error but will be ignored.
6698ac
6698ac
Add a helper function in driver.h to be used by providers code and fix
6698ac
wrong mask checks where the above was found to be applicable.
6698ac
6698ac
Signed-off-by: Noa Osherovich <noaos@mellanox.com>
6698ac
Reviewed-by: Yishai Hadas <yishaih@mellanox.com>
6698ac
(cherry picked from commit ad4419019a006938731035a766b67838678e6048)
6698ac
---
6698ac
 libibverbs/driver.h    | 5 +++++
6698ac
 providers/mlx4/verbs.c | 4 ++--
6698ac
 providers/mlx5/verbs.c | 3 ++-
6698ac
 3 files changed, 9 insertions(+), 3 deletions(-)
6698ac
6698ac
diff --git a/libibverbs/driver.h b/libibverbs/driver.h
6698ac
index 887412de..0b2cd089 100644
6698ac
--- a/libibverbs/driver.h
6698ac
+++ b/libibverbs/driver.h
6698ac
@@ -330,6 +330,11 @@ static inline int verbs_get_srq_num(struct ibv_srq *srq, uint32_t *srq_num)
6698ac
 	return ENOSYS;
6698ac
 }
6698ac
 
6698ac
+static inline bool check_comp_mask(uint64_t input, uint64_t supported)
6698ac
+{
6698ac
+	return (input & ~supported) == 0;
6698ac
+}
6698ac
+
6698ac
 int ibv_query_gid_type(struct ibv_context *context, uint8_t port_num,
6698ac
 		       unsigned int index, enum ibv_gid_type *type);
6698ac
 #endif /* INFINIBAND_DRIVER_H */
6698ac
diff --git a/providers/mlx4/verbs.c b/providers/mlx4/verbs.c
6698ac
index b966ef2c..7c8f9da8 100644
6698ac
--- a/providers/mlx4/verbs.c
6698ac
+++ b/providers/mlx4/verbs.c
6698ac
@@ -919,8 +919,8 @@ static struct ibv_qp *create_qp_ex(struct ibv_context *context,
6698ac
 		goto err_free;
6698ac
 
6698ac
 	if (mlx4qp_attr) {
6698ac
-		if (mlx4qp_attr->comp_mask &
6698ac
-		    ~(MLX4DV_QP_INIT_ATTR_MASK_RESERVED - 1)) {
6698ac
+		if (!check_comp_mask(mlx4qp_attr->comp_mask,
6698ac
+		    MLX4DV_QP_INIT_ATTR_MASK_RESERVED - 1)) {
6698ac
 			errno = EINVAL;
6698ac
 			goto err_free;
6698ac
 		}
6698ac
diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c
6698ac
index 2315a0d9..6506bc36 100644
6698ac
--- a/providers/mlx5/verbs.c
6698ac
+++ b/providers/mlx5/verbs.c
6698ac
@@ -433,7 +433,8 @@ static struct ibv_cq_ex *create_cq(struct ibv_context *context,
6698ac
 	cmd.cqe_size = cqe_sz;
6698ac
 
6698ac
 	if (mlx5cq_attr) {
6698ac
-		if (mlx5cq_attr->comp_mask & ~(MLX5DV_CQ_INIT_ATTR_MASK_RESERVED - 1)) {
6698ac
+		if (!check_comp_mask(mlx5cq_attr->comp_mask,
6698ac
+				     MLX5DV_CQ_INIT_ATTR_MASK_RESERVED - 1)) {
6698ac
 			mlx5_dbg(fp, MLX5_DBG_CQ,
6698ac
 				   "Unsupported vendor comp_mask for create_cq\n");
6698ac
 			errno = EINVAL;
6698ac
-- 
6698ac
2.12.1
6698ac