[v2,1/2] RDMA/uverbs: Fix the check for port number

From: Ismail, Mustafa
Date: Wed Jul 19 2017 - 16:34:40 EST


The port number is only valid if IB_QP_PORT is set in the mask.
So only check port number if it is valid to prevent modify_qp from
failing due to an invalid port number.

Fixes: 5ecce4c9b17b("Check port number supplied by user verbs cmds")
Cc: <stable@xxxxxxxxxxxxxxx> # v2.6.14+
Reviewed-by: Steve Wise <swise@xxxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Mustafa Ismail <mustafa.ismail@xxxxxxxxx>
Tested-by: Mike Marciniszyn <mike.marciniszyn@xxxxxxxxx>
---
drivers/infiniband/core/uverbs_cmd.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index 8ba9bfb..19de068 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -1935,7 +1935,8 @@ static int modify_qp(struct ib_uverbs_file *file,
goto out;
}

- if (!rdma_is_port_valid(qp->device, cmd->base.port_num)) {
+ if ((cmd->base.attr_mask & IB_QP_PORT) &&
+ !rdma_is_port_valid(qp->device, cmd->base.port_num)) {

FWIW,

Reviewed-by: Yuval Shaia <yuval.shaia@xxxxxxxxxx>

and/or

Tested-by: Yuval Shaia <yuval.shaia@xxxxxxxxxx>


ret = -EINVAL;
goto release_qp;
}