Fix vhost-user buffer over-read on ram hot-unplug
PATCH 1/1 Fix vhost-user buffer over-read on ram hot-unplug
The VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS vhost-user protocol feature introduced a shadow-table, used by the backend to dynamically determine how a vdev's memory regions have changed since the last vhost_user_set_mem_table() call. On hot-remove, a memmove() operation is used to overwrite the removed shadow region descriptor(s). The size parameter of this memmove was off by 1 such that if a VM with a backend supporting the VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS filled it's shadow-table (by performing the maximum number of supported hot-add operatons) and attempted to remove the last region, Qemu would read an out of bounds value and potentially crash.
This change fixes the memmove() bounds such that this erroneous read can never happen.
--- hw/virtio/vhost-user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/vhost-user.c +1 -1
@@ -672,7 +672,7 @@ static int send_remove_regions(struct vhost_dev *dev,memmove (&u->shadow_regions[shadow_reg_idx], &u->shadow_regions[shadow_reg_idx +1 ],sizeof (struct vhost_memory_region ) * - (u->num_shadow_regions - shadow_reg_idx)); + (u->num_shadow_regions - shadow_reg_idx -1 )); u->num_shadow_regions--; }
Signature · 1 line
1.8.3.1
ping
Quoted 38 lines · Raphael Norwitz
The
VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTSvhost-user protocol feature introduced a shadow-table, used by the backend to dynamically determine how a vdev's memory regions have changed since the lastvhost_user_set_mem_table()call. On hot-remove, amemmove()operation is used to overwrite the removed shadow region descriptor(s). The size parameter of this memmove was off by 1 such that if a VM with a backend supporting theVHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTSfilled it's shadow-table (by performing the maximum number of supported hot-add operatons) and attempted to remove the last region, Qemu would read an out of bounds value and potentially crash.This change fixes the
memmove()bounds such that this erroneous read can never happen.Signed-off-by Peter Turschmid <[email protected]>Signed-off-by Raphael Norwitz <[email protected]>--- hw/virtio/vhost-user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/virtio/vhost-user.c +1
-2@@ -672,7 +672,7 @@ static int send_remove_regions(struct vhost_dev *dev,memmove (&u->shadow_regions[shadow_reg_idx], &u->shadow_regions[shadow_reg_idx +1 ],sizeof (struct vhost_memory_region ) * - (u->num_shadow_regions - shadow_reg_idx)); + (u->num_shadow_regions - shadow_reg_idx -1 )); u->num_shadow_regions--; } --1.8.3.1
Quoted 12 lines · Raphael Norwitz
The
VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTSvhost-user protocol feature introduced a shadow-table, used by the backend to dynamically determine how a vdev's memory regions have changed since the lastvhost_user_set_mem_table()call. On hot-remove, amemmove()operation is used to overwrite the removed shadow region descriptor(s). The size parameter of this memmove was off by 1 such that if a VM with a backend supporting theVHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTSfilled it's shadow-table (by performing the maximum number of supported hot-add operatons) and attempted to remove the last region, Qemu would read an out of bounds value and potentially crash.
Quoted 5 lines
This change fixes the
memmove()bounds such that this erroneous read can never happen.Signed-off-by Peter Turschmid <[email protected]>Signed-off-by Raphael Norwitz <[email protected]>
Quoted 20 lines
--- hw/virtio/vhost-user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/virtio/vhost-user.c +1
-2@@ -672,7 +672,7 @@ static int send_remove_regions(struct vhost_dev *dev,memmove (&u->shadow_regions[shadow_reg_idx], &u->shadow_regions[shadow_reg_idx +1 ],sizeof (struct vhost_memory_region ) * - (u->num_shadow_regions - shadow_reg_idx)); + (u->num_shadow_regions - shadow_reg_idx -1 )); u->num_shadow_regions--; } --1.8.3.1