Linux RDMA and InfiniBand development
 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 04/13] RDMA/bng_re: Add ucontext/mmap verbs
Date: Sat, 05 Dec 2026 16:10:08 +0000	[thread overview]
Message-ID: <sashiko-outbox-251728@kernel.org> (raw)
In-Reply-To: <20261204155249.1002019-5-siva.kallam@broadcom.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] RDMA/bng_re: doorbell page size mismatch between DPI math and
  FW init
- [Medium] RDMA/bng_re: silently ignores short udata input in
  bng_re_alloc_ucontext()
- [Medium] RDMA/bng_re: missing trailing zero-fill on response in
  bng_re_alloc_ucontext()
- [Medium] RDMA/bng_re: unratelimited KERN_ERR log flooding in
  bng_re_alloc_ucontext()
- [Low] RDMA/bng_re: wrong printk format specifiers in
  bng_re_dealloc_dpi()
--

commit 511e878f370833248f60a01e5aa8d21ada2aaf78
Author: Siva Reddy Kallam <siva.kallam@broadcom.com>

RDMA/bng_re: Add ucontext/mmap verbs

This patch adds ucontext allocation, deallocation, disassociation, and
mmap verbs to the bng_re driver, along with DPI allocation and
deallocation helpers and the ucontext UAPI definitions.

> diff --git a/drivers/infiniband/hw/bng_re/bng_res.c b/drivers/infiniband/hw/bng_re/bng_res.c
> index c5f9fff56726d..6fbe88001eba4 100644
> --- a/drivers/infiniband/hw/bng_re/bng_res.c
> +++ b/drivers/infiniband/hw/bng_re/bng_res.c

[ ... ]

> +int bng_re_dealloc_dpi(struct bng_re_res *res,
> +		       struct bng_re_dpi *dpi)
> +{
> +	struct bng_re_dpi_tbl *dpit = &res->dpi_tbl;
> +	int rc = 0;
> +
> +	mutex_lock(&res->dpi_tbl_lock);
> +	if (dpi->bit >= dpit->max) {
> +		dev_warn(&res->pdev->dev,
> +			 "Invalid DPI? dpi = %d, bit = %d\n",
> +			 dpi->dpi, dpi->bit);
> +		rc = -EINVAL;
> +		goto release;
> +	}
> +
> +	/* Check ownership first so a repeated free cannot unmap anything */
> +	if (test_and_set_bit(dpi->bit, dpit->tbl)) {
> +		dev_warn(&res->pdev->dev,
> +			 "Freeing an unused DPI? dpi = %d, bit = %d\n",
> +			 dpi->dpi, dpi->bit);
> +		dev_warn(&res->pdev->dev,
> +			 "umdbr = %lld, dbr = %p, type = %d\n",
> +			 dpi->umdbr, dpi->dbr, dpi->type);
> +		dev_warn(&res->pdev->dev,
> +			 "dpit max = %d, priv_db = %p\n",
> +			 dpit->max, dpit->priv_db);

[Severity: Low]
Should these dev_warn() calls use unsigned format specifiers?  dpi->dpi,
dpi->bit, and dpit->max are u32 (so a repeated free after setting dpi->bit
to U32_MAX prints bit = -1 with %d instead of %u), and dpi->umdbr is a u64
BAR address that should use %#llx or %llu rather than %lld.

> diff --git a/drivers/infiniband/hw/bng_re/bng_res.h b/drivers/infiniband/hw/bng_re/bng_res.h
> index cc1872f3ab54d..b43827ee1b184 100644
> --- a/drivers/infiniband/hw/bng_re/bng_res.h
> +++ b/drivers/infiniband/hw/bng_re/bng_res.h

[ ... ]

> +/*
> + * HW doorbell page size. bnge does not program db_page_size through
> + * HWRM_FUNC_CFG, so firmware uses its 4KB default. DPI numbers are in
> + * units of this size, independent of the CPU PAGE_SIZE; each DPI handed
> + * to user space still owns a full CPU page so mappings never overlap.
> + */
> +#define BNG_RE_DB_PAGE_SIZE	SZ_4K

[Severity: Medium]
Does hardcoding BNG_RE_DB_PAGE_SIZE to SZ_4K conflict with the doorbell
page size programmed into RoCE firmware?

bng_re_init_rcfw() configures firmware to use host PAGE_SIZE instead of
the 4KB default:

drivers/infiniband/hw/bng_re/bng_fw.c:bng_re_init_rcfw() {
	...
	req.log2_dbr_pg_size = cpu_to_le16(PAGE_SHIFT -
					   BNG_FW_DBR_BASE_PAGE_SHIFT);
	...
}

On hosts where PAGE_SIZE > 4KB (such as 64KB arm64), DPI numbers computed
in bng_res_alloc_dpi_tbl() and bng_re_alloc_dpi() in 4KB units disagree
with firmware's doorbell page size by PAGE_SIZE / SZ_4K, so user DPIs
passed to firmware are mis-indexed or rejected.

> diff --git a/drivers/infiniband/hw/bng_re/bng_verbs.c b/drivers/infiniband/hw/bng_re/bng_verbs.c
> index 6750dfa4a1680..45ade397342aa 100644
> --- a/drivers/infiniband/hw/bng_re/bng_verbs.c
> +++ b/drivers/infiniband/hw/bng_re/bng_verbs.c

[ ... ]

> +	if (udata->inlen >= sizeof(ureq)) {
> +		rc = ib_copy_from_udata(&ureq, udata, sizeof(ureq));
> +		if (rc)
> +			return rc;
> +		if (udata->inlen > sizeof(ureq) &&
> +		    !ib_is_udata_cleared(udata, sizeof(ureq),
> +					 udata->inlen - sizeof(ureq)))
> +			return -EOPNOTSUPP;
> +		if (ureq.comp_mask & ~BNG_RE_COMP_MASK_REQ_UCNTX_SUPPORTED)
> +			return -EOPNOTSUPP;
> +	}

[Severity: Medium]
Can a truncated non-empty udata buffer bypass input validation here?

When 0 < udata->inlen < sizeof(ureq) (such as a 4-byte payload via uverbs
write()), this block is skipped and the call succeeds instead of returning
-EINVAL.

Using if (udata->inlen) with ib_copy_validate_udata_in_cm() rejects short
inputs while keeping the trailing-zero and comp_mask checks.

[ ... ]

> +	rc = ib_copy_to_udata(udata, &resp, min(udata->outlen, sizeof(resp)));

[Severity: Medium]
Does this leave trailing userspace response bytes unzeroed when
udata->outlen > sizeof(resp)?

The RDMA udata ABI contract requires zero-filling any response bytes beyond
sizeof(resp) so newer userspace expecting an extended bng_re_uctx_resp does
not read uninitialized bytes from its output buffer.  Switching to
ib_respond_udata(udata, resp) handles the copy and trailing clear_user().

> +	if (rc) {
> +		ibdev_err(ibdev, "Failed to copy user context");
> +		rc = -EFAULT;
> +		goto copy_udata_fail;
> +	}

[Severity: Medium]
Can an unprivileged user flood the kernel log with this unratelimited
ibdev_err()?

Supplying an unwritable outbuf fails GET_CONTEXT without installing
ufile->ucontext, so a single open uverbs fd can repeat the call in a tight
loop and emit a KERN_ERR line every time.  The unratelimited dev_err() in
bng_re_get_user_dpi() has the same issue once DPIs are exhausted.

Switching to ib_respond_udata() (which logs EFAULT with ibdev_dbg()) and
downgrading or ratelimiting the bng_re_get_user_dpi() message avoids both.

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

  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 [this message]
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
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-251728@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox