mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Abhijit Gangurde <abhijit.gangurde@amd.com>
To: <jgg@ziepe.ca>, <leon@kernel.org>
Cc: <allen.hubbe@amd.com>, <nikhil.agarwal@amd.com>,
	<linux-rdma@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	"Abhijit Gangurde" <abhijit.gangurde@amd.com>
Subject: [for-next v2 1/3] RDMA/ionic: Bound user queue depth and stride before shifting
Date: Thu, 26 Nov 2026 10:18:08 +0530	[thread overview]
Message-ID: <20261126044811.3458258-2-abhijit.gangurde@amd.com> (raw)
In-Reply-To: <20261126044811.3458258-1-abhijit.gangurde@amd.com>

ionic_validate_qdesc() uses depth_log2 and stride_log2 from the user
request as shift counts without an upper bound. Both are u8, so
BIT(depth_log2) and BIT_ULL(depth_log2 + stride_log2) can shift by the
width of the type or more, which is undefined behaviour.

Where the shift count wraps, as on x86-64, the size check can be
bypassed. With depth_log2 = 4, mask = 15 and stride_log2 = 60, the
required size BIT_ULL(64) evaluates to 1, so a one page ring passes
validation with a depth and stride it cannot hold.

Reject a depth_log2 above order_base_2(IONIC_MAX_DEPTH), and a
depth_log2 + stride_log2 of BITS_PER_LONG_LONG or more, before either
shift.

Fixes: f3bdbd42702c ("RDMA/ionic: Create device queues to support admin operations")
Signed-off-by: Abhijit Gangurde <abhijit.gangurde@amd.com>
---
 drivers/infiniband/hw/ionic/ionic_controlpath.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/infiniband/hw/ionic/ionic_controlpath.c b/drivers/infiniband/hw/ionic/ionic_controlpath.c
index 8a0a1575a339..8a304d576852 100644
--- a/drivers/infiniband/hw/ionic/ionic_controlpath.c
+++ b/drivers/infiniband/hw/ionic/ionic_controlpath.c
@@ -23,6 +23,13 @@ static int ionic_validate_qdesc(struct ionic_qdesc *q)
 	if (q->addr & (PAGE_SIZE - 1))
 		return -EINVAL;
 
+	/* Keep the shift counts below within the width of their types */
+	if (q->depth_log2 > order_base_2(IONIC_MAX_DEPTH))
+		return -EINVAL;
+
+	if (q->depth_log2 + q->stride_log2 >= BITS_PER_LONG_LONG)
+		return -EINVAL;
+
 	if (q->mask != BIT(q->depth_log2) - 1)
 		return -EINVAL;
 
-- 
2.43.0


  reply	other threads:[~2026-11-26  4:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  4:48 [for-next v2 0/3] RDMA/ionic: Accept CQ, SQ, and RQ rings as umem attributes Abhijit Gangurde
2026-11-26  4:48 ` Abhijit Gangurde [this message]
2026-11-26  4:48 ` [for-next v2 2/3] RDMA/ionic: Accept CQ ring buffers as ioctl " Abhijit Gangurde
2026-11-26  4:48 ` [for-next v2 3/3] RDMA/ionic: Accept QP SQ and RQ rings " Abhijit Gangurde

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=20261126044811.3458258-2-abhijit.gangurde@amd.com \
    --to=abhijit.gangurde@amd.com \
    --cc=allen.hubbe@amd.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=nikhil.agarwal@amd.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

all inboxes | Powered by JetHome®