All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Jinpu Wang <jinpu.wang@cloud.ionos.com>
Cc: qemu-devel@nongnu.org, Li Zhijian <lizhijian@fujitsu.com>,
	Samuel Zhang <guoqing.zhang@amd.com>,
	Fabiano Rosas <farosas@suse.de>,
	Juraj Marcin <jmarcin@redhat.com>,
	Yanfei Xu <yanfei.xu@bytedance.com>
Subject: Re: [PATCH 08/10] migration/rdma: Sanity check RDMA_CONTROL_REGISTER_REQUEST chunks
Date: Wed, 19 Aug 2026 11:20:54 -0400	[thread overview]
Message-ID: <aoXJ1k8N_bzfXs5u@x1.local> (raw)
In-Reply-To: <CAMGffEkzdOna79f561r6bMF3wgZw4h5LwHXhC3KBx_FqLNz+wQ@mail.gmail.com>

On Wed, Aug 19, 2026 at 03:00:51PM +0200, Jinpu Wang wrote:
> On Mon, Aug 17, 2026 at 10:24 PM Peter Xu <peterx@redhat.com> wrote:
> >
> > The value received on wire for head.chunks when registering new RDMA
> > regions is not correctly checked.  Logically the value can still make
> > ram_chunk_start() (of ram_chunk_end()) to overflow, having a result pointer
> > very small, smaller than RDMALocalBlock.local_host_addr.
> >
> > Add the sanity check.
> >
> > Reported-by: Tristan (@TristanInSec)
> > Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4011
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> >  migration/rdma.c | 7 +++++++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/migration/rdma.c b/migration/rdma.c
> > index 5ce8b06818..bbbc40ea3b 100644
> > --- a/migration/rdma.c
> > +++ b/migration/rdma.c
> > @@ -3401,6 +3401,13 @@ int rdma_registration_handle(QEMUFile *f)
> >                  chunk = ram_chunk_index(block->local_host_addr,
> >                                          (uint8_t *) host_addr);
> >                  chunk_start = ram_chunk_start(block, chunk);
> > +                if (chunk + reg->chunks > block->nb_chunks) {
> > +                    error_report("%s: head.chunks contains illegal value"
> > +                                 " (chunk=%"PRIu64", chunks=%"PRIu64", "
> > +                                 "nb_chunks=%d)", __func__, chunk,
> > +                                 reg->chunks, block->nb_chunks);
> > +                    goto err;
> > +                }
> safer to do this instead, as reg->chunks is from wire:
> uint64_t chunk_sum;
> if (uadd64_overflow(chunk, reg->chunks, &chunk_sum) ||
>     chunk_sum > block->nb_chunks) {
>     error_report(...);
>     goto err;
> }

I thought I covered that, I even mentioned the overflow in the commit log,
but I didn't really do anything..

When looking at this again, I found reg->chunks is defined in a weird way,
instead of "number of chunks", it's off-by-one...

qemu_rdma_write_one():
    chunks = length / chunk_size;
    if (chunks && ((length % chunk_size) == 0)) {
        chunks--;
    }

So I think I should check it with "chunk_sum >= block->nb_chunks" to be
accurate.  Diff attached to be squashed when repost, please help double
check:

diff --git a/migration/rdma.c b/migration/rdma.c
index 6384306ead..e976739fad 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -3393,7 +3393,7 @@ int rdma_registration_handle(QEMUFile *f)
             }

             for (int count = 0; count < head.repeat; count++) {
-                uint64_t chunk;
+                uint64_t chunk, chunk_sum;
                 uint8_t *chunk_start, *chunk_end;

                 reg = &registers[count];
@@ -3424,7 +3424,8 @@ int rdma_registration_handle(QEMUFile *f)
                 chunk = ram_chunk_index(block->local_host_addr,
                                         (uint8_t *) host_addr);
                 chunk_start = ram_chunk_start(block, chunk);
-                if (chunk + reg->chunks > block->nb_chunks) {
+                if (uadd64_overflow(chunk, reg->chunks, &chunk_sum) ||
+                    chunk_sum >= block->nb_chunks) {
                     error_report("%s: head.chunks contains illegal value"
                                  " (chunk=%"PRIu64", chunks=%"PRIu64", "
                                  "nb_chunks=%d)", __func__, chunk,

Thanks for the careful review,

-- 
Peter Xu



  reply	other threads:[~2026-08-19 15:21 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-17 20:24 [PATCH 00/10] migration/rdma: Fixes or drops Peter Xu
2026-08-17 20:24 ` [PATCH 01/10] migration/rdma: Introduce RDMA_CONTROL_NUM Peter Xu
2026-08-19 10:35   ` Jinpu Wang
2026-08-17 20:24 ` [PATCH 02/10] migration/rdma: Remove unregister code Peter Xu
2026-08-18 11:57   ` Yanfei Xu
2026-08-18 13:01     ` Peter Xu
2026-08-18 13:57       ` Yanfei Xu
2026-08-18 14:43         ` Peter Xu
2026-08-19  3:55           ` Yanfei Xu
2026-08-19 10:52   ` Jinpu Wang
2026-08-19 12:01     ` Jinpu Wang
2026-08-19 12:47       ` Peter Xu
2026-08-19 13:20         ` Jinpu Wang
2026-08-17 20:24 ` [PATCH 03/10] migration/rdma: Stick with rdma_ prefix for all tracepoints Peter Xu
2026-08-19 11:39   ` Jinpu Wang
2026-08-17 20:24 ` [PATCH 04/10] migration/rdma: Drop RDMALocalBlock.is_ram_block Peter Xu
2026-08-19 12:43   ` Jinpu Wang
2026-08-19 14:49     ` Peter Xu
2026-08-17 20:24 ` [PATCH 05/10] migration/rdma: Drop RDMALocalBlock.unregister_bitmap Peter Xu
2026-08-19 12:44   ` Jinpu Wang
2026-08-17 20:24 ` [PATCH 06/10] migration/rdma: Drop RDMARegister.key.chunk Peter Xu
2026-08-19 12:48   ` Jinpu Wang
2026-08-17 20:24 ` [PATCH 07/10] migration/rdma: Sanity check RDMA_CONTROL_REGISTER_REQUEST on buflen Peter Xu
2026-08-19 12:52   ` Jinpu Wang
2026-08-17 20:24 ` [PATCH 08/10] migration/rdma: Sanity check RDMA_CONTROL_REGISTER_REQUEST chunks Peter Xu
2026-08-19 13:00   ` Jinpu Wang
2026-08-19 15:20     ` Peter Xu [this message]
2026-08-19 17:29       ` Jinpu Wang
2026-08-17 20:24 ` [PATCH 09/10] migration/rdma: Sanity check upper bound of register MR address Peter Xu
2026-08-19 13:09   ` Jinpu Wang
2026-08-17 20:24 ` [PATCH 10/10] migration/rdma: Sanity check compress request ranges Peter Xu
2026-08-19 13:10   ` Jinpu Wang

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=aoXJ1k8N_bzfXs5u@x1.local \
    --to=peterx@redhat.com \
    --cc=farosas@suse.de \
    --cc=guoqing.zhang@amd.com \
    --cc=jinpu.wang@cloud.ionos.com \
    --cc=jmarcin@redhat.com \
    --cc=lizhijian@fujitsu.com \
    --cc=qemu-devel@nongnu.org \
    --cc=yanfei.xu@bytedance.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.