Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Jacob Moroni <jmoroni@google.com>
To: tatyana.e.nikolova@intel.com, jgg@ziepe.ca, leon@kernel.org
Cc: linux-rdma@vger.kernel.org, jdz@google.com,
	 Jacob Moroni <jmoroni@google.com>
Subject: [PATCH rdma-next 4/8] RDMA/irdma: Validate legacy user QP sizes
Date: Mon, 30 Nov 2026 01:33:03 +0000	[thread overview]
Message-ID: <20261130013307.2848330-5-jmoroni@google.com> (raw)
In-Reply-To: <20261130013307.2848330-1-jmoroni@google.com>

A user context without IRDMA_ALLOC_UCTX_USE_RAW_ATTR passes SQ and RQ
sizes in units of WQEs, which the kernel then multiplies by the WQE
size to get the actual ring sizes. Only the values from user space
are checked against the HW limits and there is no lower bound
enforced.

An SQ size of zero gives an empty ring, which causes a divide by
zero in the various ring macros. The resulting ring sizes (post
multiplication) can also exceed the HW limits.

Fix this by rejecting an empty SQ and ring sizes above max_hw_wq_quanta
and max_hw_rq_quanta, similar to how it's done for the current ABI.

Fixes: b48c24c2d710 ("RDMA/irdma: Implement device supported verb APIs")
Signed-off-by: Jacob Moroni <jmoroni@google.com>
---
 drivers/infiniband/hw/irdma/verbs.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c
index 93328b0abcbd..de727270ab87 100644
--- a/drivers/infiniband/hw/irdma/verbs.c
+++ b/drivers/infiniband/hw/irdma/verbs.c
@@ -677,6 +677,7 @@ static int irdma_setup_umode_qp(struct irdma_ucontext *ucontext,
 				struct uverbs_attr_bundle *attrs)
 {
 	struct irdma_qp_uk_init_info *ukinfo = &info->qp_uk_init_info;
+	u32 sq_quanta, rq_quanta;
 	unsigned long flags;
 	int ret;
 
@@ -696,6 +697,12 @@ static int irdma_setup_umode_qp(struct irdma_ucontext *ucontext,
 		ukinfo->rq_size = init_attr->cap.max_recv_wr;
 		irdma_uk_calc_shift_wq(ukinfo, &ukinfo->sq_shift,
 				       &ukinfo->rq_shift);
+		sq_quanta = ukinfo->sq_size << ukinfo->sq_shift;
+		rq_quanta = ukinfo->rq_size << ukinfo->rq_shift;
+		if (!sq_quanta ||
+		    sq_quanta > ukinfo->uk_attrs->max_hw_wq_quanta ||
+		    rq_quanta > ukinfo->uk_attrs->max_hw_rq_quanta)
+			return -EINVAL;
 	} else {
 		ret = irdma_uk_calc_depth_shift_sq(ukinfo, &ukinfo->sq_depth,
 						   &ukinfo->sq_shift);
-- 
2.56.1.839.g22a8290db9-goog


  parent reply	other threads:[~2026-11-30  1:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  1:32 [PATCH rdma-next 0/8] RDMA/irdma: Fix validation of user and iWARP input Jacob Moroni
2026-11-30  1:33 ` [PATCH rdma-next 1/8] RDMA/irdma: Fix QP ID leak when QP creation fails early Jacob Moroni
2026-11-30  1:33 ` [PATCH rdma-next 2/8] RDMA/irdma: Fix SRQ ID leak when the SRQ depth is rejected Jacob Moroni
2026-11-30  1:33 ` [PATCH rdma-next 3/8] RDMA/irdma: Reject a PBL backed CQ shadow area Jacob Moroni
2026-11-30  1:33 ` Jacob Moroni [this message]
2026-11-30  1:33 ` [PATCH rdma-next 5/8] RDMA/irdma: Check user queue buffers against the queue size Jacob Moroni
2026-11-30  1:33 ` [PATCH rdma-next 6/8] RDMA/irdma: Validate iWARP TCP header lengths Jacob Moroni
2026-11-30  1:33 ` [PATCH rdma-next 7/8] RDMA/irdma: Validate iWARP TCP option lengths Jacob Moroni
2026-11-30  1:33 ` [PATCH rdma-next 8/8] RDMA/irdma: Fix MPA v2 private data length handling Jacob Moroni
2026-11-30  1:44 ` [PATCH rdma-next 0/8] RDMA/irdma: Fix validation of user and iWARP input sashiko-bot

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=20261130013307.2848330-5-jmoroni@google.com \
    --to=jmoroni@google.com \
    --cc=jdz@google.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --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