From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796487011; b=WTfwZV74McC0usgNn/WNTUmjBWtnwa98uC2W37lnz22wnmUBs/kYm2sfjepKaN+iQNZ5 jFOTR9ZH4SUUIPkx/w07tCbe9al0OueL+3LAbFR3Xu3eGW/b1fmr1vuLM1PNe+HOZ72cd eogHzsAR297kYz2DgwGJyZt+9QuvfdDp2xs0lg0DsFxbtIulxH1XeM1lb2xWO2Mo7v30T 4pOx4sU3tyfPh4aO2cVtqJjcWC3aqJ/N8YWzqaLR7OKXohca6hHFrrqYp4Ih9ild4AgZS iZdLAe6hwVo54kBX4IkTyvNEI+BOQPPX+l07SMOziVrEd4kGfHo5PC2bpcCekOFRAbg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796487011; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=8mUvOvSpFxnn+z6Gp8iIeRUDW4smgFVnZX0F/XlaCis=; b=xqZfatCb5rojB/9SanCgf7rJUe+3jizhWB6q3OvN2KnY9skdQMQjenHmkWOLU9SBwDUY 8uO/TayC2xWD6/7LkZXp67kb8n41XESdBgl8JmD+YZ1tCKqGsyTmXcHJXKlkWWXfYs701 4XOUPawVAnEtB+BnpuXxffzVAhM+K5Jhc7tsbvpRoKtpHYMGuO0h77GibMRqSB1K/GeRI kWJIOO1vmFSU0dGK0+6caaAfpvQ79gKlxJGz0Q0DtArkj1Ms6aucGvLtjFmdLvkxOhPqj p9gSKDppGzJF0PuPtxq0BtPM9QkaBjnbTAYuJhA9omb699TtgEslQtPIh/EUfHtV18w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EmKXuh+p; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA42D606A32F for ; Sat, 5 Dec 2026 16:10:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EmKXuh+p Received: by smtp.kernel.org (Postfix) with ESMTPSA id 404691F00A12; Sat, 5 Dec 2026 16:10:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796487011; bh=8mUvOvSpFxnn+z6Gp8iIeRUDW4smgFVnZX0F/XlaCis=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=EmKXuh+pwq2PGZNiQA5bHc1W3ailpolDpFh/ooCVlM1qB1HUl4b9LNXgC8KVhe0xP OyA++eSIlQZJbm/4vMp0SK2CmkdZnfVqGTh6S1bdvrqHvcRmfZmYkEPVm+ckaoQDfC ouD6PkzE1hQesyB+G76bw8F2ToUG5gSLcOzSsfRSXwlKJHV0H4KBROI44BhjTx5jxq UIr0WUFcY6p3QYWoXoYLCOUmMWwChz2/BMU81OkPnaX+lw7hOpfjdQ+wDXbVzgcW35 iZHYYGdSLXJ/HTZZFLOBYKzAoETzkNLSSzvvGuG7xODJEncYriEwPuoQkVs5rY3zlR /erVArtRP5JxA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RDMA v2 09/13] RDMA/bng_re: Add SRQ verbs Reply-To: sashiko-reviews@lists.linux.dev To: "Siva Reddy Kallam" Cc: linux-rdma@vger.kernel.org In-Reply-To: <20261204155249.1002019-10-siva.kallam@broadcom.com> References: <20261204155249.1002019-1-siva.kallam@broadcom.com> <20261204155249.1002019-10-siva.kallam@broadcom.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 16:10:10 +0000 X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 9 potential issues to consider: - [High] RDMA/bng_re: DMA UAF freeing SRQ memory on create timeout or rollback failure - [High] RDMA/bng_re: coherent DMA leak in bng_sp_query_srq() when stalled or offline - [High] RDMA/bng_re: SRQ page-size and PBL misprogramming on 16K/64K and large rings - [Medium] RDMA/bng_re: bng_re_create_srq() reads unallocated nq[0].ring_id - [Medium] RDMA/bng_re: missing RDMA udata validation helpers and log flood in SRQ verbs - [Medium] RDMA/bng_re: bng_re_modify_srq() ignores unknown srq_attr_mask bits - [Medium] RDMA/bng_re: max_srq_wqes underflow and missing cap break bng_re_create_srq() - [Medium] RDMA/bng_re: unratelimited ibdev_err() on user SRQ input in bng_verbs.c - [Low] RDMA/bng_re: raw kernel pointer passed as srq_handle in bng_sp_create_srq() -- commit a05e7c474826ef7b2affd05f8ea03f32c5588d09 Author: Suresh Rupanagudi RDMA/bng_re: Add SRQ verbs This commit implements the create, modify, query, and destroy SRQ verbs along with their slow-path firmware commands and UAPI request/response structures for the bng_re driver. > diff --git a/drivers/infiniband/hw/bng_re/bng_sp.c b/drivers/infiniband/h= w/bng_re/bng_sp.c > index a4e6692a48baa..40fe509db724c 100644 > --- a/drivers/infiniband/hw/bng_re/bng_sp.c > +++ b/drivers/infiniband/hw/bng_re/bng_sp.c > @@ -112,7 +112,10 @@ int bng_re_get_dev_attr(struct bng_re_rcfw *rcfw) > =20 > attr->max_srq =3D le16_to_cpu(sb->max_srq); > attr->max_srq_wqes =3D le32_to_cpu(sb->max_srq_wr) - 1; > - attr->max_srq_sges =3D sb->max_srq_sge; > + /* The CREATE_SRQ SGE field is only 4 bits wide */ > + attr->max_srq_sges =3D min_t(u32, sb->max_srq_sge, > + CMDQ_CREATE_SRQ_SRQ_SGE_MASK >> > + CMDQ_CREATE_SRQ_SRQ_SGE_SFT); [Severity: Medium] Can attr->max_srq_wqes underflow to U32_MAX if firmware reports sb->max_srq_wr =3D=3D 0? In bng_re_create_srq(), that lets userspace pass max_wr =3D=3D U32_MAX, wrapping max_wr + 1 to 0 and triggering undefined behavior in roundup_pow_of_two(0) (or creating a zero-sized SRQ with BNG_RE_UCNTX_CMASK_POW2_DISABLED). entries is also declared as a signed int rather than u32, and attr->max_srq_wqes is not clamped to BNG_SP_SRQ_SIZE_MAX, unlike attr->max_cq_wqes just above. [ ... ] > @@ -766,3 +769,149 @@ int bng_sp_destroy_cq(struct bng_re_res *res, struc= t bng_sp_cq *cq) > return 0; > } > =20 > +int bng_sp_create_srq(struct bng_re_res *res, struct bng_sp_srq *srq) > +{ [ ... ] > + /* Configure the request */ > + req.dpi =3D cpu_to_le32(srq->dpi->dpi); > + req.srq_handle =3D cpu_to_le64((uintptr_t)srq); [Severity: Low] Should req.srq_handle use an opaque handle instead of a raw kernel heap pointer? Passing (uintptr_t)srq exposes a kernel virtual address across the DMA boundary to firmware and sets up a raw-pointer-from-DMA pattern for future NQ SRQ event handling. bng_sp_create_cq() in the same file uses a cyclic 32-bit XArray handle from cq->nq->cq_xa, and passing an XArray ID (or 0 while NQ_BASE_TYPE_SRQ_EVENT is unhandled) avoids leaking the pointer. [ ... ] > +int bng_sp_query_srq(struct bng_re_res *res, struct bng_sp_srq *srq) > +{ [ ... ] > + /* Configure the request */ > + sbuf.size =3D ALIGN(sizeof(*sb), BNG_FW_CMDQE_UNITS); > + sbuf.sb =3D dma_alloc_coherent(&rcfw->pdev->dev, sbuf.size, > + &sbuf.dma_addr, GFP_KERNEL); > + if (!sbuf.sb) > + return -ENOMEM; > + req.resp_size =3D sbuf.size / BNG_FW_CMDQE_UNITS; > + req.srq_cid =3D cpu_to_le32(srq->id); > + sb =3D sbuf.sb; > + > + bng_re_fill_cmdqmsg(&msg, &req, &resp, &sbuf, sizeof(req), > + sizeof(resp), 0); > + rc =3D bng_re_rcfw_send_message(rcfw, &msg); > + if (!rc) > + srq->threshold =3D le16_to_cpu(sb->srq_limit) | > + ((u32)sb->srq_limit_hi << 16); > + > + /* After a timeout the command is only abandoned, firmware may still > + * write the response. Leave the small buffer allocated in that case. > + */ > + if (rc !=3D -ETIMEDOUT) > + dma_free_coherent(&rcfw->pdev->dev, sbuf.size, > + sbuf.sb, sbuf.dma_addr); > + > + return rc; > +} [Severity: High] Does bng_sp_query_srq() leak sbuf.sb on every call once firmware stalls or the PCI channel goes offline? When FIRMWARE_STALL_DETECTED is set or pci_channel_offline(rcfw->pdev) is true, __send_message_basic_sanity() rejects the command without posting it and bng_re_rcfw_send_message() still returns -ETIMEDOUT. Because cleanup only checks rc !=3D -ETIMEDOUT, an unprivileged user calling query_srq in a loop can exhaust coherent DMA memory at syscall rate. Checking bng_re_rcfw_alive() before allocation and freeing when !bng_re_fw_may_own(rcfw, rc) avoids the leak. [ ... ] > diff --git a/drivers/infiniband/hw/bng_re/bng_verbs.c b/drivers/infiniban= d/hw/bng_re/bng_verbs.c > index 8ec0a19867b5f..0f71740a254fa 100644 > --- a/drivers/infiniband/hw/bng_re/bng_verbs.c > +++ b/drivers/infiniband/hw/bng_re/bng_verbs.c > @@ -1327,3 +1327,244 @@ int bng_re_poll_cq(struct ib_cq *ibcq, int num_en= tries, struct ib_wc *wc) > */ > return 0; > } > + > +/* SRQ helper function */ > +static int bng_re_init_user_srq(struct bng_re_dev *rdev, > + struct bng_re_srq *srq, > + struct ib_udata *udata) > +{ [ ... ] > + /* srqva is mandatory, a shorter request cannot describe the ring. > + * Fields past inlen (from an older library) stay zero. > + */ > + if (udata->inlen < offsetofend(struct bng_re_srq_req, srqva)) > + return -EINVAL; > + > + if (ib_copy_from_udata(&ureq, udata, min(udata->inlen, sizeof(ureq)))) > + return -EFAULT; [Severity: Medium] Should the SRQ verbs use the standard RDMA udata validation helpers to preserve forward and backward UAPI compatibility? Using raw ib_copy_from_udata() here silently ignores non-zero trailing bytes past sizeof(ureq) instead of returning -EOPNOTSUPP via ib_copy_validate_udata_in(). Similarly, bng_re_create_srq() uses ib_copy_to_udata() instead of ib_respond_udata() (leaving trailing response bytes unzeroed when udata->outlen > sizeof(resp)), and bng_re_modify_srq() and bng_re_destroy_srq() both omit ib_no_udata_io(udata). In addition, struct bng_re_srq_req adds an unused, unvalidated srq_handle field without documenting it as reserved. > + /* The ring may start inside a page, firmware takes the offset in 4K > + * units, so a finer alignment cannot be described. > + */ > + if (!IS_ALIGNED(ureq.srqva, BIT(BNG_SP_FWO_4K_SHIFT))) > + return -EINVAL; > + > + /* Bound the ring size before pinning any user memory */ > + if (sp_srq->max_wqe > BNG_SP_SRQ_SIZE_MAX || > + check_mul_overflow((size_t)sp_srq->max_wqe, > + (size_t)sp_srq->wqe_size, &bytes)) > + return -EINVAL; > + > + bytes =3D PAGE_ALIGN(bytes); > + umem =3D ib_umem_get_va(&rdev->ibdev, ureq.srqva, bytes, > + IB_ACCESS_LOCAL_WRITE); > + if (IS_ERR(umem)) > + return PTR_ERR(umem); > + > + srq->umem =3D umem; > + sp_srq->sginfo.umem =3D umem; > + sp_srq->sginfo.pgsize =3D PAGE_SIZE; > + sp_srq->sginfo.pgshft =3D PAGE_SHIFT; > + sp_srq->fwo_offset =3D ureq.srqva & ~PAGE_MASK; [Severity: High] Can hardcoding PAGE_SIZE and PAGE_ALIGN(bytes) misprogram the SRQ page size and PBL hierarchy, causing out-of-bounds NIC DMA? On 16KB-page kernels, bng_re_base_pg_size() in bng_sp_create_srq() has no 16KB case and silently falls through to BNG_RE_HWRM_PG_SIZE_4K while the PBL holds 16KB blocks. Three other cases also break: - On PAGE_SIZE > 4K kernels, a 4KB-aligned srqva near the end of a page has its length expanded by PAGE_ALIGN(bytes) into the next (possibly unmapped) page, causing spurious -EFAULT or over-pinning. - On 4KB-page kernels with large rings (npages > 262,144), bng_re_alloc_init_hwq() sets pbl[BNG_PBL_LVL_0].pg_size to npde * PAGE_SIZE (8KB for npde =3D=3D 2), which bng_re_base_pg_size() encodes as PG_8K even though the leaf pages are 4KB. - On 64KB-page kernels with npages > 512, bng_re_alloc_init_hwq() allocates 2-level PBLs using the 4KB shift MAX_PBL_LVL_1_PGS_SHIFT while indexing with PAGE_SIZE-based PTR_PG/PTR_IDX, and bng_sp_create_srq() never sets req.pbl_pg_size or CMDQ_CREATE_SRQ_FLAGS_PBL_PG_SIZE_VALID. Using bng_re_setup_sginfo() (as in bng_re_create_user_cq()) and bounding npages to single-PDE capacity avoids these mismatches. [ ... ] > + if (srq_init_attr->attr.max_wr > dev_attr->max_srq_wqes) { > + ibdev_err(&rdev->ibdev, "Create SRQ failed - max exceeded\n"); > + rc =3D -EINVAL; > + goto exit; > + } > + > + if (srq_init_attr->attr.max_sge > dev_attr->max_srq_sges) { > + ibdev_err(&rdev->ibdev, > + "Create SRQ failed - max_sge %u exceeds supported %u\n", > + srq_init_attr->attr.max_sge, dev_attr->max_srq_sges); > + rc =3D -EINVAL; > + goto exit; > + } [Severity: Medium] Can an unprivileged user flood kernel logs by passing invalid SRQ parameters? These ibdev_err() calls, along with the ones on ib_copy_to_udata() failure in bng_re_create_srq() and unsupported srq_attr_mask in bng_re_modify_srq(), are unratelimited and directly reachable from uverbs. Using ibdev_dbg() as in bng_re_create_user_cq() avoids log spam. [ ... ] > + srq->sp_srq.eventq_hw_ring_id =3D rdev->nqr->nq[0].ring_id; [Severity: Medium] Can rdev->nqr->nq[0] be unallocated here when the device has only BNG_RE_MIN_MSIX (2) MSI-X vectors? bng_re_dev_init() allows probe to succeed with 2 vectors, which equals BNG_RE_MAX_RSVD_IRQ, so bng_fp_alloc_nq_res() allocates zero fast-path NQs and leaves nq[0].ring_id as 0. Using bng_re_get_nq() as CQ creation does rejects that case with -ENODEV and load-balances across NQs when multiple exist. [ ... ] > + rc =3D bng_sp_create_srq(&rdev->bng_res, &srq->sp_srq); > + if (rc) { > + ibdev_err(&rdev->ibdev, "Create HW SRQ failed!\n"); > + goto fail; > + } > + > + resp.srqid =3D srq->sp_srq.id; > + rc =3D ib_copy_to_udata(udata, &resp, min(sizeof(resp), udata->outlen)); > + if (rc) { > + ibdev_err(&rdev->ibdev, "SRQ copy to udata failed!\n"); > + if (bng_sp_destroy_srq(&rdev->bng_res, &srq->sp_srq)) { > + /* Create fails, so the core drops the SRQ and nothing > + * can retry the destroy. Release the queue memory > + * instead of leaking it. > + */ > + ibdev_err(&rdev->ibdev, "Rollback of SRQ %u failed\n", > + srq->sp_srq.id); > + bng_re_free_hwq(&rdev->bng_res, &srq->sp_srq.hwq); > + } > + goto fail; > + } > + > + return 0; > + > +fail: > + ib_umem_release(srq->umem); [Severity: High] Can both error paths here cause a DMA use-after-free of the SRQ PBL and user ring pages? If CREATE_SRQ times out while the PCI channel is still online, firmware may still process the abandoned command and DMA to the queue, yet bng_sp_create_srq() unconditionally calls bng_re_free_hwq() and bng_re_create_srq() releases srq->umem. Likewise, if an unprivileged caller triggers ib_copy_to_udata() failure on an already-created SRQ and rollback bng_sp_destroy_srq() fails, firmware still owns the live SRQ, so freeing srq->sp_srq.hwq and releasing srq->umem unmaps memory under active hardware DMA. Checking bng_re_rcfw_alive() before creation and keeping HWQ and umem pinned when bng_re_fw_may_own() is true or rollback destroy fails matches bng_re_create_user_cq() and bng_re_destroy_srq(). [ ... ] > + if (srq_attr_mask & IB_SRQ_MAX_WR) { > + /* SRQ resize is not supported */ > + ibdev_dbg(&rdev->ibdev, "SRQ resize is not supported\n"); > + return -EINVAL; > + } > + > + if (srq_attr_mask & IB_SRQ_LIMIT) { [Severity: Medium] Does bng_re_modify_srq() silently ignore unsupported bits in srq_attr_mask when IB_SRQ_LIMIT is also set? ib_uverbs_modify_srq() forwards cmd.attr_mask directly from userspace without masking unknown bits, so checking srq_attr_mask !=3D IB_SRQ_LIMIT (or rejecting srq_attr_mask & ~IB_SRQ_LIMIT) is needed to avoid accepting unknown attributes. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204155249.1002= 019-1-siva.kallam@broadcom.com?part=3D9