[for-next v2 1/3] RDMA/ionic: Bound user queue depth and stride before shifting

From: Abhijit Gangurde

Date: Wed Nov 25 2026 - 23:50:35 EST


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@xxxxxxx>
---
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