On Tue, Oct 27, 2015 at 10:47:56AM +0200, Michael S. Tsirkin wrote: > + for (i = 0; i < *num_sg; i++) { > len = sg[i].iov_len; > sg[i].iov_base = cpu_physical_memory_map(addr[i], &len, is_write); > - if (sg[i].iov_base == NULL || len != sg[i].iov_len) { > + if (!sg[i].iov_base) { > error_report("virtio: error trying to map MMIO memory"); > exit(1); > } > + if (len == sg[i].iov_len) { > + continue; > + } > + if (*num_sg >= max_size) { > + error_report("virtio: memory split makes iovec too large"); > + exit(1); > + } > + memcpy(sg + i + 1, sg + i, sizeof(*sg) * (*num_sg - i)); > + memcpy(addr + i + 1, addr + i, sizeof(*addr) * (*num_sg - i));
These should be memmove() since memcpy() arguments are not allowed to overlap.