All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Siva Reddy Kallam" <siva.kallam@broadcom.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [RDMA v2 09/13] RDMA/bng_re: Add SRQ verbs
Date: Sat, 05 Dec 2026 16:10:10 +0000	[thread overview]
Message-ID: <sashiko-outbox-251733@kernel.org> (raw)
In-Reply-To: <20261204155249.1002019-10-siva.kallam@broadcom.com>

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 <suresh.rupanagudi@broadcom.com>

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/hw/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)
>  
>  	attr->max_srq = le16_to_cpu(sb->max_srq);
>  	attr->max_srq_wqes = le32_to_cpu(sb->max_srq_wr) - 1;
> -	attr->max_srq_sges = sb->max_srq_sge;
> +	/* The CREATE_SRQ SGE field is only 4 bits wide */
> +	attr->max_srq_sges = 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 == 0?

In bng_re_create_srq(), that lets userspace pass max_wr == 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, struct bng_sp_cq *cq)
>  	return 0;
>  }
>  
> +int bng_sp_create_srq(struct bng_re_res *res, struct bng_sp_srq *srq)
> +{

[ ... ]

> +	/* Configure the request */
> +	req.dpi = cpu_to_le32(srq->dpi->dpi);
> +	req.srq_handle = 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 = ALIGN(sizeof(*sb), BNG_FW_CMDQE_UNITS);
> +	sbuf.sb = dma_alloc_coherent(&rcfw->pdev->dev, sbuf.size,
> +				     &sbuf.dma_addr, GFP_KERNEL);
> +	if (!sbuf.sb)
> +		return -ENOMEM;
> +	req.resp_size = sbuf.size / BNG_FW_CMDQE_UNITS;
> +	req.srq_cid = cpu_to_le32(srq->id);
> +	sb = sbuf.sb;
> +
> +	bng_re_fill_cmdqmsg(&msg, &req, &resp, &sbuf, sizeof(req),
> +			    sizeof(resp), 0);
> +	rc = bng_re_rcfw_send_message(rcfw, &msg);
> +	if (!rc)
> +		srq->threshold = 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 != -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 != -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/infiniband/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_entries, 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 = PAGE_ALIGN(bytes);
> +	umem = ib_umem_get_va(&rdev->ibdev, ureq.srqva, bytes,
> +			      IB_ACCESS_LOCAL_WRITE);
> +	if (IS_ERR(umem))
> +		return PTR_ERR(umem);
> +
> +	srq->umem = umem;
> +	sp_srq->sginfo.umem = umem;
> +	sp_srq->sginfo.pgsize = PAGE_SIZE;
> +	sp_srq->sginfo.pgshft = PAGE_SHIFT;
> +	sp_srq->fwo_offset = 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 == 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 = -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 = -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 = 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 = 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 = srq->sp_srq.id;
> +	rc = 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 != IB_SRQ_LIMIT
(or rejecting srq_attr_mask & ~IB_SRQ_LIMIT) is needed to avoid accepting
unknown attributes.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204155249.1002019-1-siva.kallam@broadcom.com?part=9

  reply	other threads:[~2026-12-05 16:10 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 15:47 [RDMA v2 00/13] Add BNG_RE control path verbs Siva Reddy Kallam
2026-12-04 15:47 ` [RDMA v2 01/13] bnge: Keep the RoCE MSI-X minimum for the MPC vector Siva Reddy Kallam
2026-12-04 15:47 ` [RDMA v2 02/13] RDMA/bng_re: Add MPC, XID management, doorbell infrastructure Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:47 ` [RDMA v2 03/13] RDMA/bng_re: Add support verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:47 ` [RDMA v2 04/13] RDMA/bng_re: Add ucontext/mmap verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:47 ` [RDMA v2 05/13] RDMA/bng_re: Add GID verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:47 ` [RDMA v2 06/13] RDMA/bng_re: Add PD verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:47 ` [RDMA v2 07/13] RDMA/bng_re: Add MR verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:48 ` [RDMA v2 08/13] RDMA/bng_re: Add CQ verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:48 ` [RDMA v2 09/13] RDMA/bng_re: Add SRQ verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot [this message]
2026-12-04 15:48 ` [RDMA v2 10/13] RDMA/bng_re: Add Stats verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:48 ` [RDMA v2 11/13] RDMA/bng_re: Add AH verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:48 ` [RDMA v2 12/13] RDMA/bng_re: Add QP verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:48 ` [RDMA v2 13/13] RDMA/bng_re: Register with ib-core Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-05 16:10 ` [RDMA v2 00/13] Add BNG_RE control path verbs sashiko-bot

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=sashiko-outbox-251733@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=siva.kallam@broadcom.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.