From: Bernard Metzler <bernard.metzler@linux.dev>
To: Andrew Stellman <astellman@stellman-greene.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH rdma-rc] RDMA/siw: Honor the sg_offset in siw_map_mr_sg()
Date: Thu, 26 Nov 2026 18:31:41 +0100 [thread overview]
Message-ID: <7d940be4-913f-4324-b1a3-1f72ee90be45@linux.dev> (raw)
In-Reply-To: <20261122191128.65369-1-astellman@stellman-greene.com>
On 22.11.2026 20:11, Andrew Stellman wrote:
> siw_map_mr_sg() builds the first PBL entry from sg_dma_address() and
> sg_dma_len() of the first scatterlist entry and ignores *sg_off.
> ib_sg_to_pages() includes *sg_off in mr->iova, which siw stores as
> mem->va, so siw_pbl_get_buffer() resolves an address in the MR to a
> location *sg_off bytes before it. rdma_rw_ctx_init() passes its
> sg_offset to ib_map_mr_sg(), and isert can pass a nonzero offset.
>
> A test module registered a one page buffer on siw with ib_map_mr_sg()
> and sg_offset 0x200, which gave mr->iova at page offset 0x200 and
> mr->length 3584. A user space client then wrote 16 bytes with an RDMA
> WRITE at mr->iova. The bytes landed at page offset 0x000 of the buffer
> instead of 0x200. With sg_offset 0 they landed at page offset 0x000,
> as expected.
>
> Start the first PBL entry *sg_off bytes into the first scatterlist
> entry, and reject an offset past the end of that entry, as
> ib_sg_to_pages() does. With this change the bytes land at page offset
> 0x200.
>
> The issue was found by Claude Opus 5.5 running Quality Playbook, an
> LLM-driven code review tool:
> https://github.com/andrewstellman/quality-playbook
> The fix and this changelog were drafted with Claude Opus 5.5 and
> reviewed by me.
>
> Fixes: 303ae1cdfdf7 ("rdma/siw: application interface")
> Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
> ---
> Tested in QEMU on v7.4-rc3 with KASAN, with an in-kernel test module
> and a librdmacm client over siw. A reproducer is available on request.
>
> drivers/infiniband/sw/siw/siw_verbs.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/infiniband/sw/siw/siw_verbs.c b/drivers/infiniband/sw/siw/siw_verbs.c
> index 80ef4cb95fc..c5f67c8e7ce 100644
> --- a/drivers/infiniband/sw/siw/siw_verbs.c
> +++ b/drivers/infiniband/sw/siw/siw_verbs.c
> @@ -1505,8 +1505,15 @@ int siw_map_mr_sg(struct ib_mr *base_mr, struct scatterlist *sl, int num_sle,
> return -EINVAL;
> }
> if (i == 0) {
> - pble->addr = sg_dma_address(slp);
> - pble->size = sg_dma_len(slp);
> + unsigned int off = sg_off ? *sg_off : 0;
> +
> + /* The MR starts *sg_off bytes into the first entry */
> + if (off > sg_dma_len(slp)) {
> + siw_dbg_mem(mem, "sg_off %u beyond first SGE\n", off);
> + return -EINVAL;
> + }
> + pble->addr = sg_dma_address(slp) + off;
> + pble->size = sg_dma_len(slp) - off;
> pble->pbl_off = 0;
> pbl_size = pble->size;
> pbl->num_buf = 1;
Excellent catch. Thanks very much, and sorry for the late reply.
Acked-by: Bernard Metzler <bernard.metzler@linux.dev>
prev parent reply other threads:[~2026-11-26 17:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 19:11 Andrew Stellman
2026-11-26 8:57 ` Leon Romanovsky
2026-11-26 17:31 ` Bernard Metzler [this message]
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=7d940be4-913f-4324-b1a3-1f72ee90be45@linux.dev \
--to=bernard.metzler@linux.dev \
--cc=astellman@stellman-greene.com \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
/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
all inboxes | Powered by JetHome®