linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sindhu Devale <sindhu.devale@intel.com>
To: jgg@nvidia.com, leon@kernel.org, tatyana.e.nikolova@intel.com
Cc: linux-rdma@vger.kernel.org, shiraz.saleem@intel.com,
	mustafa.ismail@intel.com, "Sindhu,
	Devale" <sindhu.devale@intel.com>
Subject: [PATCH rdma-core 2/2] providers/irdma: Validate input before memory window bind
Date: Mon, 29 Nov 2021 16:54:46 -0600	[thread overview]
Message-ID: <20211129225446.691-3-sindhu.devale@intel.com> (raw)
In-Reply-To: <20211129225446.691-1-sindhu.devale@intel.com>

From: "Sindhu, Devale" <sindhu.devale@intel.com>

Check for a non null MR, address and length
before allowing bind operation.

Also, add check to make sure the MR and MW are in
same PD before posting a bind MW op.

Fixes: 14a0fc824f16 ("rdma-core/irdma: Implement device supported verb APIs")
Signed-off-by: Sindhu, Devale <sindhu.devale@intel.com>
---
 providers/irdma/uverbs.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/providers/irdma/uverbs.c b/providers/irdma/uverbs.c
index c8222d14..dc7cf41a 100644
--- a/providers/irdma/uverbs.c
+++ b/providers/irdma/uverbs.c
@@ -206,19 +206,30 @@ int irdma_ubind_mw(struct ibv_qp *qp, struct ibv_mw *mw,
 		   struct ibv_mw_bind *mw_bind)
 {
 	struct ibv_mw_bind_info	*bind_info = &mw_bind->bind_info;
-	struct verbs_mr *vmr = verbs_get_mr(bind_info->mr);
-	struct irdma_umr *umr = container_of(vmr, struct irdma_umr, vmr);
+	struct verbs_mr *vmr;
+	struct irdma_umr *umr;
 
 	struct ibv_send_wr wr = {};
 	struct ibv_send_wr *bad_wr;
 	int err;
 
-	if (vmr->mr_type != IBV_MR_TYPE_MR || mw->type != IBV_MW_TYPE_1)
-		return ENOTSUP;
-
-	if (umr->acc_flags & IBV_ACCESS_ZERO_BASED)
+	if (!bind_info->mr && (bind_info->addr || bind_info->length))
 		return EINVAL;
 
+	if (bind_info->mr) {
+		vmr = verbs_get_mr(bind_info->mr);
+		umr = container_of(vmr, struct irdma_umr, vmr);
+
+		if (vmr->mr_type != IBV_MR_TYPE_MR || mw->type != IBV_MW_TYPE_1)
+			return ENOTSUP;
+
+		if (umr->acc_flags & IBV_ACCESS_ZERO_BASED)
+			return EINVAL;
+
+		if (mw->pd != bind_info->mr->pd)
+			return EPERM;
+	}
+
 	wr.opcode = IBV_WR_BIND_MW;
 	wr.bind_mw.bind_info = mw_bind->bind_info;
 	wr.bind_mw.mw = mw;
-- 
2.32.0


  parent reply	other threads:[~2021-11-29 22:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-29 22:54 [PATCH rdma-core 0/2] Validate input and fix return code Sindhu Devale
2021-11-29 22:54 ` [PATCH rdma-core 1/2] providers/irdma: Report correct WC errors Sindhu Devale
2021-11-29 22:54 ` Sindhu Devale [this message]
2021-11-30 12:21 ` [PATCH rdma-core 0/2] Validate input and fix return code Leon Romanovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211129225446.691-3-sindhu.devale@intel.com \
    --to=sindhu.devale@intel.com \
    --cc=jgg@nvidia.com \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mustafa.ismail@intel.com \
    --cc=shiraz.saleem@intel.com \
    --cc=tatyana.e.nikolova@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).