]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
RDMA/irdma: Prevent zero-length STAG registration
authorChristopher Bednarz <christopher.n.bednarz@intel.com>
Fri, 18 Aug 2023 14:48:38 +0000 (09:48 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Sep 2023 07:48:33 +0000 (09:48 +0200)
[ Upstream commit bb6d73d9add68ad270888db327514384dfa44958 ]

Currently irdma allows zero-length STAGs to be programmed in HW during
the kernel mode fast register flow. Zero-length MR or STAG registration
disable HW memory length checks.

Improve gaps in bounds checking in irdma by preventing zero-length STAG or
MR registrations except if the IB_PD_UNSAFE_GLOBAL_RKEY is set.

This addresses the disclosure CVE-2023-25775.

Fixes: b48c24c2d710 ("RDMA/irdma: Implement device supported verb APIs")
Signed-off-by: Christopher Bednarz <christopher.n.bednarz@intel.com>
Signed-off-by: Shiraz Saleem <shiraz.saleem@intel.com>
Link: https://lore.kernel.org/r/20230818144838.1758-1-shiraz.saleem@intel.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/infiniband/hw/irdma/ctrl.c
drivers/infiniband/hw/irdma/type.h
drivers/infiniband/hw/irdma/verbs.c

index 45e3344daa048f123f6f3971566f8cfebf72eb2e..ef47ec271e19e698fd04b1ac342d8bc6e09373ed 100644 (file)
@@ -1061,6 +1061,9 @@ static int irdma_sc_alloc_stag(struct irdma_sc_dev *dev,
        u64 hdr;
        enum irdma_page_size page_size;
 
+       if (!info->total_len && !info->all_memory)
+               return -EINVAL;
+
        if (info->page_size == 0x40000000)
                page_size = IRDMA_PAGE_SIZE_1G;
        else if (info->page_size == 0x200000)
@@ -1126,6 +1129,9 @@ static int irdma_sc_mr_reg_non_shared(struct irdma_sc_dev *dev,
        u8 addr_type;
        enum irdma_page_size page_size;
 
+       if (!info->total_len && !info->all_memory)
+               return -EINVAL;
+
        if (info->page_size == 0x40000000)
                page_size = IRDMA_PAGE_SIZE_1G;
        else if (info->page_size == 0x200000)
index a20709577ab0ada080750c4a1c4713fab7cbe939..3b1fa5bc0a585ebe16e26b60f2c648258ffadfbe 100644 (file)
@@ -971,6 +971,7 @@ struct irdma_allocate_stag_info {
        bool remote_access:1;
        bool use_hmc_fcn_index:1;
        bool use_pf_rid:1;
+       bool all_memory:1;
        u8 hmc_fcn_index;
 };
 
@@ -998,6 +999,7 @@ struct irdma_reg_ns_stag_info {
        bool use_hmc_fcn_index:1;
        u8 hmc_fcn_index;
        bool use_pf_rid:1;
+       bool all_memory:1;
 };
 
 struct irdma_fast_reg_stag_info {
index 8f9378767f307c566d530b7ffa6256057d9918a8..20d70f0d21e0f11d5ca0a1b5db6bd7a78701dce5 100644 (file)
@@ -2552,7 +2552,8 @@ static int irdma_hw_alloc_stag(struct irdma_device *iwdev,
                               struct irdma_mr *iwmr)
 {
        struct irdma_allocate_stag_info *info;
-       struct irdma_pd *iwpd = to_iwpd(iwmr->ibmr.pd);
+       struct ib_pd *pd = iwmr->ibmr.pd;
+       struct irdma_pd *iwpd = to_iwpd(pd);
        int status;
        struct irdma_cqp_request *cqp_request;
        struct cqp_cmds_info *cqp_info;
@@ -2568,6 +2569,7 @@ static int irdma_hw_alloc_stag(struct irdma_device *iwdev,
        info->stag_idx = iwmr->stag >> IRDMA_CQPSQ_STAG_IDX_S;
        info->pd_id = iwpd->sc_pd.pd_id;
        info->total_len = iwmr->len;
+       info->all_memory = pd->flags & IB_PD_UNSAFE_GLOBAL_RKEY;
        info->remote_access = true;
        cqp_info->cqp_cmd = IRDMA_OP_ALLOC_STAG;
        cqp_info->post_sq = 1;
@@ -2615,6 +2617,8 @@ static struct ib_mr *irdma_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
        iwmr->type = IRDMA_MEMREG_TYPE_MEM;
        palloc = &iwpbl->pble_alloc;
        iwmr->page_cnt = max_num_sg;
+       /* Use system PAGE_SIZE as the sg page sizes are unknown at this point */
+       iwmr->len = max_num_sg * PAGE_SIZE;
        err_code = irdma_get_pble(iwdev->rf->pble_rsrc, palloc, iwmr->page_cnt,
                                  false);
        if (err_code)
@@ -2694,7 +2698,8 @@ static int irdma_hwreg_mr(struct irdma_device *iwdev, struct irdma_mr *iwmr,
 {
        struct irdma_pbl *iwpbl = &iwmr->iwpbl;
        struct irdma_reg_ns_stag_info *stag_info;
-       struct irdma_pd *iwpd = to_iwpd(iwmr->ibmr.pd);
+       struct ib_pd *pd = iwmr->ibmr.pd;
+       struct irdma_pd *iwpd = to_iwpd(pd);
        struct irdma_pble_alloc *palloc = &iwpbl->pble_alloc;
        struct irdma_cqp_request *cqp_request;
        struct cqp_cmds_info *cqp_info;
@@ -2713,6 +2718,7 @@ static int irdma_hwreg_mr(struct irdma_device *iwdev, struct irdma_mr *iwmr,
        stag_info->total_len = iwmr->len;
        stag_info->access_rights = irdma_get_mr_access(access);
        stag_info->pd_id = iwpd->sc_pd.pd_id;
+       stag_info->all_memory = pd->flags & IB_PD_UNSAFE_GLOBAL_RKEY;
        if (stag_info->access_rights & IRDMA_ACCESS_FLAGS_ZERO_BASED)
                stag_info->addr_type = IRDMA_ADDR_TYPE_ZERO_BASED;
        else