]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
RDMA/irdma: Fix OOB read during CQ MR registration
authorJacob Moroni <jmoroni@google.com>
Tue, 2 Jun 2026 21:44:23 +0000 (21:44 +0000)
committerJason Gunthorpe <jgg@nvidia.com>
Fri, 5 Jun 2026 17:09:29 +0000 (14:09 -0300)
Sashiko pointed out an unrelated bug during a previous patch:
https://sashiko.dev/#/patchset/20260512183852.614045-1-jmoroni%40google.com

This change fixes the bug by eliminating the cqmr->split field which
was not being set properly and instead just checks the CQ resize
feature flag directly.

The cqmr->split field essentially tracks whether IRDMA_FEATURE_CQ_RESIZE
is set, but it was not being set until CQ creation time, which is _after_
CQ memory registration (the only other place where it is referenced).

As a result, it would always be false during MR registration and would
therefore cause irdma_handle_q_mem to populate cqmr->shadow even for GEN_2
HW and beyond:

    cqmr->shadow = (dma_addr_t)arr[req->cq_pages];

The issue is that for GEN_2 and beyond, req->cq_pages may be exactly equal
to iwmr->page_cnt and therefore equal to the size of arr, which would cause
an OOB read by one.

Fixes: b48c24c2d710 ("RDMA/irdma: Implement device supported verb APIs")
Link: https://patch.msgid.link/r/20260602214423.1315105-2-jmoroni@google.com
Signed-off-by: Jacob Moroni <jmoroni@google.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/hw/irdma/verbs.c
drivers/infiniband/hw/irdma/verbs.h

index 284dfba4e9842ebdb5e4144bd69f7db13e0e0b0f..231b2854bb146120b945c24e9c7439a2191b1434 100644 (file)
@@ -2557,7 +2557,6 @@ static int irdma_create_cq(struct ib_cq *ibcq,
                        }
                        cqmr_shadow = &iwpbl_shadow->cq_mr;
                        info.shadow_area_pa = cqmr_shadow->cq_pbl.addr;
-                       cqmr->split = true;
                } else {
                        info.shadow_area_pa = cqmr->shadow;
                }
@@ -2961,7 +2960,8 @@ static int irdma_handle_q_mem(struct irdma_device *iwdev,
        case IRDMA_MEMREG_TYPE_CQ:
                hmc_p = &cqmr->cq_pbl;
 
-               if (!cqmr->split)
+               if (!(iwdev->rf->sc_dev.hw_attrs.uk_attrs.feature_flags &
+                     IRDMA_FEATURE_CQ_RESIZE))
                        cqmr->shadow = (dma_addr_t)arr[req->cq_pages];
 
                if (lvl)
index aabbb3442098bc32dd1656ec363d962d3c51d588..289ebc9b23ca78116595cd261e430d1e9dca432d 100644 (file)
@@ -65,7 +65,6 @@ struct irdma_hmc_pble {
 struct irdma_cq_mr {
        struct irdma_hmc_pble cq_pbl;
        dma_addr_t shadow;
-       bool split;
 };
 
 struct irdma_srq_mr {