virtio/virtio_mem: handle a possible NULL as a memcpy parameter
authorPeng Hao <flyingpenghao@gmail.com>
Wed, 22 Dec 2021 01:12:25 +0000 (09:12 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Jan 2022 10:02:59 +0000 (11:02 +0100)
commit cf4a4493ff70874f8af26d75d4346c591c298e89 upstream.

There is a check for vm->sbm.sb_states before, and it should check
it here as well.

Signed-off-by: Peng Hao <flyingpeng@tencent.com>
Link: https://lore.kernel.org/r/20211222011225.40573-1-flyingpeng@tencent.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Fixes: 5f1f79bbc9e2 ("virtio-mem: Paravirtualized memory hotplug")
Cc: stable@vger.kernel.org # v5.8+
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/virtio/virtio_mem.c

index bef8ad6..4624a2c 100644 (file)
@@ -577,7 +577,7 @@ static int virtio_mem_sbm_sb_states_prepare_next_mb(struct virtio_mem *vm)
                return -ENOMEM;
 
        mutex_lock(&vm->hotplug_mutex);
-       if (new_bitmap)
+       if (vm->sbm.sb_states)
                memcpy(new_bitmap, vm->sbm.sb_states, old_pages * PAGE_SIZE);
 
        old_bitmap = vm->sbm.sb_states;