From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Jack Wang <jinpu.wang@ionos.com>, Peter Xu <peterx@redhat.com>,
Li Zhijian <lizhijian@fujitsu.com>,
Juraj Marcin <jmarcin@redhat.com>,
Fabiano Rosas <farosas@suse.de>,
Samuel Zhang <guoqing.zhang@amd.com>,
Yanfei Xu <yanfei.xu@bytedance.com>,
Jinpu Wang <jinpu.wang@cloud.ionos.com>
Subject: [PATCH v2 07/10] migration/rdma: Sanity check RDMA_CONTROL_REGISTER_REQUEST on buflen
Date: Thu, 20 Aug 2026 16:03:19 -0400 [thread overview]
Message-ID: <20260820200322.3321036-8-peterx@redhat.com> (raw)
In-Reply-To: <20260820200322.3321036-1-peterx@redhat.com>
RDMA header supports head.repeat on RDMA_CONTROL_REGISTER_REQUEST, which
can include >1 memory registrations. The current code did check over
head.repeat to guard against RDMA_CONTROL_MAX_COMMANDS_PER_MESSAGE, however
it didn't further check the buffer size (head.len) to make sure the
received data is large enough to include the repeated entries. Check it.
This is almost only to harden this piece of code, in reality on source side
QEMU never uses repeat>1.. However since it's a protocol, still keep it.
Check the buffer size instead.
In case it's not obvious to new RDMA readers: head.len should be the size
RDMA has last received, as qemu_rdma_exchange_get_response() checked on it
against byte_len (which was further fetched from ibv_wc.byte_len in
qemu_rdma_poll()).
Reported-by: Tristan (@TristanInSec)
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4028
Reviewed-by: Jinpu Wang <jinpu.wang@cloud.ionos.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
migration/rdma.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/migration/rdma.c b/migration/rdma.c
index 683c24ba4d..f7356e759f 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -3360,6 +3360,14 @@ int rdma_registration_handle(QEMUFile *f)
reg_resp.repeat = head.repeat;
registers = (RDMARegister *) rdma->wr_data[idx].control_curr;
+ /* Making sure the register buffers to read are valid */
+ if (head.len != head.repeat * sizeof(RDMARegister)) {
+ error_report("%s: Invalid RDMA_CONTROL_REGISTER_REQUEST "
+ "(head.repeat=%"PRIu32", head.len=%"PRIu32")",
+ __func__, head.repeat, head.len);
+ goto err;
+ }
+
for (int count = 0; count < head.repeat; count++) {
uint64_t chunk;
uint8_t *chunk_start, *chunk_end;
--
2.54.0
next prev parent reply other threads:[~2026-08-20 20:04 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-20 20:03 [PATCH v2 00/10] migration/rdma: Fixes or drops Peter Xu
2026-08-20 20:03 ` [PATCH v2 01/10] migration/rdma: Introduce RDMA_CONTROL_NUM Peter Xu
2026-08-21 13:17 ` Fabiano Rosas
2026-08-20 20:03 ` [PATCH v2 02/10] migration/rdma: Remove unregister code Peter Xu
2026-08-20 20:03 ` [PATCH v2 03/10] migration/rdma: Stick with rdma_ prefix for all tracepoints Peter Xu
2026-08-20 20:03 ` [PATCH v2 04/10] migration/rdma: Drop RDMALocalBlock.is_ram_block Peter Xu
2026-08-21 13:21 ` Fabiano Rosas
2026-08-20 20:03 ` [PATCH v2 05/10] migration/rdma: Drop RDMALocalBlock.unregister_bitmap Peter Xu
2026-08-20 20:03 ` [PATCH v2 06/10] migration/rdma: Drop RDMARegister.key.chunk Peter Xu
2026-08-20 20:03 ` Peter Xu [this message]
2026-08-21 13:30 ` [PATCH v2 07/10] migration/rdma: Sanity check RDMA_CONTROL_REGISTER_REQUEST on buflen Fabiano Rosas
2026-08-20 20:03 ` [PATCH v2 08/10] migration/rdma: Sanity check RDMA_CONTROL_REGISTER_REQUEST chunks Peter Xu
2026-08-21 13:33 ` Fabiano Rosas
2026-08-20 20:03 ` [PATCH v2 09/10] migration/rdma: Sanity check upper bound of register MR address Peter Xu
2026-08-21 13:34 ` Fabiano Rosas
2026-08-20 20:03 ` [PATCH v2 10/10] migration/rdma: Sanity check compress request ranges Peter Xu
2026-08-21 13:36 ` Fabiano Rosas
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=20260820200322.3321036-8-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=farosas@suse.de \
--cc=guoqing.zhang@amd.com \
--cc=jinpu.wang@cloud.ionos.com \
--cc=jinpu.wang@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.