From c4233c368af858b39036d1b6f80ee0e616d17796 Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Mon, 13 Jul 2015 13:42:03 +0200 Subject: [PATCH 23/58] Sanity check RDMA remote data Message-id: <1436794926-1598-15-git-send-email-dgilbert@redhat.com> Patchwork-id: 66983 O-Subject: [RHEL-7.2 qemu-kvm-rhev PATCH 14/17] Sanity check RDMA remote data Bugzilla: 1210715 RH-Acked-by: Marcel Apfelbaum RH-Acked-by: Laszlo Ersek RH-Acked-by: Juan Quintela From: "Dr. David Alan Gilbert" Perform some basic (but probably not complete) sanity checking on requests from the RDMA source. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael R. Hines Signed-off-by: Juan Quintela (cherry picked from commit afcddefdbe75d0c20bf6e11b5512ba768ce0700c) Signed-off-by: Miroslav Rezanina --- migration/rdma.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/migration/rdma.c b/migration/rdma.c index 7b582db..f3e0a82 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -2991,6 +2991,13 @@ static int qemu_rdma_registration_handle(QEMUFile *f, void *opaque) trace_qemu_rdma_registration_handle_compress(comp->length, comp->block_idx, comp->offset); + if (comp->block_idx >= rdma->local_ram_blocks.nb_blocks) { + error_report("rdma: 'compress' bad block index %u (vs %d)", + (unsigned int)comp->block_idx, + rdma->local_ram_blocks.nb_blocks); + ret = -EIO; + break; + } block = &(rdma->local_ram_blocks.block[comp->block_idx]); host_addr = block->local_host_addr + @@ -3079,8 +3086,23 @@ static int qemu_rdma_registration_handle(QEMUFile *f, void *opaque) trace_qemu_rdma_registration_handle_register_loop(count, reg->current_index, reg->key.current_addr, reg->chunks); + if (reg->current_index >= rdma->local_ram_blocks.nb_blocks) { + error_report("rdma: 'register' bad block index %u (vs %d)", + (unsigned int)reg->current_index, + rdma->local_ram_blocks.nb_blocks); + ret = -ENOENT; + break; + } block = &(rdma->local_ram_blocks.block[reg->current_index]); if (block->is_ram_block) { + if (block->offset > reg->key.current_addr) { + error_report("rdma: bad register address for block %s" + " offset: %" PRIx64 " current_addr: %" PRIx64, + block->block_name, block->offset, + reg->key.current_addr); + ret = -ERANGE; + break; + } host_addr = (block->local_host_addr + (reg->key.current_addr - block->offset)); chunk = ram_chunk_index(block->local_host_addr, @@ -3089,6 +3111,14 @@ static int qemu_rdma_registration_handle(QEMUFile *f, void *opaque) chunk = reg->key.chunk; host_addr = block->local_host_addr + (reg->key.chunk * (1UL << RDMA_REG_CHUNK_SHIFT)); + /* Check for particularly bad chunk value */ + if (host_addr < (void *)block->local_host_addr) { + error_report("rdma: bad chunk for block %s" + " chunk: %" PRIx64, + block->block_name, reg->key.chunk); + ret = -ERANGE; + break; + } } chunk_start = ram_chunk_start(block, chunk); chunk_end = ram_chunk_end(block, chunk + reg->chunks); -- 1.8.3.1