From: sashiko-bot@kernel.org
To: "Konstantin Taranov" <kotaranov@linux.microsoft.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH rdma-next v4 01/10] RDMA/mana_ib: Allocate and map fast-registration MRs
Date: Sat, 10 Oct 2026 07:07:22 +0000 [thread overview]
Message-ID: <sashiko-outbox-166293@kernel.org> (raw)
In-Reply-To: <20261010065443.3554193-2-kotaranov@linux.microsoft.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] rdma: missing bounds check on max_num_sg leading to integer overflow and OOB write
- [Low] rdma: hardware structure defined using compiler-dependent C bitfields
--
commit 7ef4d39c8200798999dc9e55ae57d45e1ec08621
Author: Konstantin Taranov <kotaranov@microsoft.com>
RDMA/mana_ib: Allocate and map fast-registration MRs
Implement alloc_mr and map_mr_sg for memory-registration MRs.
> diff --git a/drivers/infiniband/hw/mana/mana_ib.h b/drivers/infiniband/hw/mana/mana_ib.h
> index 9173ca64d2e1e..da9b48b422a1c 100644
> --- a/drivers/infiniband/hw/mana/mana_ib.h
> +++ b/drivers/infiniband/hw/mana/mana_ib.h
[ ... ]
> +#define MANA_FMR_MST_ALIGNMENT 64
> +
> +struct mana_fmr_mst_entry {
> + u32 reserved1;
> + u32 reserved2 : 8;
> + u32 page_size : 5;
> + u32 reserved3 : 3;
> + u32 access_right : 8;
> + u32 addr_type : 2;
> + u32 reserved4 : 6;
> + u32 reserved5[2];
> + u64 start_va;
> + u64 length;
> + u32 reserved6[8];
> +}; /* HW DATA */
[Severity: Low]
This structure defines a hardware interface but uses C bitfields. Are there
risks of compiler-dependent memory layout causing portability issues when used
for hardware ABI?
> +
> +static inline u32 mana_ib_fmr_header_offset(u32 num_ptes)
> +{
> + /* The header follows the PTEs with the required MST alignment. */
> + return ALIGN(sizeof(u64) * num_ptes, MANA_FMR_MST_ALIGNMENT);
> +}
[Severity: High]
Could sizeof(u64) * num_ptes produce a 64-bit value that is silently truncated
by the u32 return type when num_ptes is very large?
[ ... ]
> diff --git a/drivers/infiniband/hw/mana/mr.c b/drivers/infiniband/hw/mana/mr.c
> index 1233685b4b890..34dcc50d0be96 100644
> --- a/drivers/infiniband/hw/mana/mr.c
> +++ b/drivers/infiniband/hw/mana/mr.c
[ ... ]
> +struct ib_mr *mana_ib_alloc_mr(struct ib_pd *ibpd, enum ib_mr_type mr_type,
> + u32 max_num_sg)
> +{
> + struct mana_ib_pd *pd = container_of(ibpd, struct mana_ib_pd, ibpd);
> + struct gdma_create_mr_params mr_params = {};
> + struct gdma_context *gc;
> + struct mana_ib_dev *dev;
> + struct mana_ib_mr *mr;
> + int err;
> +
> + dev = container_of(ibpd->device, struct mana_ib_dev, ib_dev);
> + gc = mdev_to_gc(dev);
> +
> + if (mr_type != IB_MR_TYPE_MEM_REG)
> + return ERR_PTR(-EOPNOTSUPP);
> +
> + mr = kzalloc_obj(*mr);
> + if (!mr)
> + return ERR_PTR(-ENOMEM);
> +
> + mr->fmr.max_ptes = max_num_sg;
> + mr->fmr.size = mana_ib_fmr_buf_sz(max_num_sg);
> + mr->fmr.ptes = dma_alloc_coherent(gc->dev, mr->fmr.size, &mr->fmr.dma_handle,
> + GFP_KERNEL);
[Severity: High]
Since max_num_sg is used without validation, is it possible for an excessively
large value to result in an undersized allocation for mr->fmr.ptes, given the
potential truncation in mana_ib_fmr_header_offset() called by
mana_ib_fmr_buf_sz()?
[ ... ]
> +static int mana_ib_set_page(struct ib_mr *ibmr, u64 addr)
> +{
> + struct mana_ib_mr *mr = container_of(ibmr, struct mana_ib_mr, ibmr);
> +
> + if (mr->fmr.pte_count >= mr->fmr.max_ptes)
> + return -ENOMEM;
> +
> + mr->fmr.ptes[mr->fmr.pte_count] = addr | MANA_PTE_VALID_MASK;
> + mr->fmr.pte_count++;
> +
> + return 0;
> +}
[Severity: High]
If mr->fmr.size was truncated to a small value, but mr->fmr.max_ptes retains
the original large max_num_sg value, would this bounds check be insufficient to
prevent out-of-bounds writes into memory past the allocated DMA buffer?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261010065443.3554193-1-kotaranov@linux.microsoft.com?part=1
next prev parent reply other threads:[~2026-10-10 7:07 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-10 6:54 [PATCH rdma-next v4 00/10] RDMA/mana_ib: Add kernel RC and fast registration support Konstantin Taranov
2026-10-10 6:54 ` [PATCH rdma-next v4 01/10] RDMA/mana_ib: Allocate and map fast-registration MRs Konstantin Taranov
2026-10-10 7:07 ` sashiko-bot [this message]
2026-10-10 6:54 ` [PATCH rdma-next v4 02/10] RDMA/mana: Create and destroy kernel RC QPs Konstantin Taranov
2026-10-10 7:11 ` sashiko-bot
2026-10-10 6:54 ` [PATCH rdma-next v4 03/10] net/mana: Extend GDMA encoding for new RDMA WQEs Konstantin Taranov
2026-10-10 7:11 ` sashiko-bot
2026-10-10 6:54 ` [PATCH rdma-next v4 04/10] RDMA/mana_ib: Maintain kernel RC QP state Konstantin Taranov
2026-10-10 7:13 ` sashiko-bot
2026-10-10 6:54 ` [PATCH rdma-next v4 05/10] RDMA/mana_ib: Post receive WRs on kernel RC QPs Konstantin Taranov
2026-10-10 7:08 ` sashiko-bot
2026-10-10 6:54 ` [PATCH rdma-next v4 06/10] RDMA/mana_ib: Post send and memory-management WRs on " Konstantin Taranov
2026-10-10 7:15 ` sashiko-bot
2026-10-10 6:54 ` [PATCH rdma-next v4 07/10] RDMA/mana_ib: Poll RC completions using PSN and FSN progress Konstantin Taranov
2026-10-10 7:11 ` sashiko-bot
2026-10-10 6:54 ` [PATCH rdma-next v4 08/10] RDMA/mana_ib: Flush and notify CQs when kernel QPs enter ERR Konstantin Taranov
2026-10-10 7:15 ` sashiko-bot
2026-10-10 6:54 ` [PATCH rdma-next v4 09/10] RDMA/mana_ib: Handle error CQEs for RC QPs Konstantin Taranov
2026-10-10 7:11 ` sashiko-bot
2026-10-10 6:54 ` [PATCH rdma-next v4 10/10] RDMA/mana_ib: Drain kernel receive and send queues Konstantin Taranov
2026-10-10 7:13 ` 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-166293@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kotaranov@linux.microsoft.com \
--cc=linux-rdma@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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