hw/char/virtio-serial-bus: validate nr_active_ports from migration stream
PATCH 1/1 hw/char/virtio-serial-bus: validate nr_active_ports from migration stream
The migration restore path reads nr_active_ports from the incoming stream and passes it directly to fetch_active_ports_list(), which uses it to size a heap allocation. A crafted migration stream can set this field to a very large value, causing QEMU to attempt a multi-gigabyte allocation and abort.
Fix this by checking nr_active_ports against the configured max_virtserial_ports before calling fetch_active_ports_list().
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3801
--- hw/char/virtio-serial-bus.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/char/virtio-serial-bus.c +4 -0
@@ -804,6 +804,10 @@ static int virtio_serial_load_device(VirtIODevice *vdev, QEMUFile *f,qemu_get_be32s (f, &nr_active_ports); +if (nr_active_ports > max_nr_ports) { +return -EINVAL ; + } +if (nr_active_ports) { ret =fetch_active_ports_list (f, s, nr_active_ports);if (ret) {
Signature · 1 line
2.54.0
Quoted 9 lines · Laurent Vivier
The migration restore path reads
nr_active_portsfrom the incoming stream and passes it directly tofetch_active_ports_list(), which uses it to size a heap allocation. A crafted migration stream can set this field to a very large value, causing QEMU to attempt a multi-gigabyte allocation and abort.Fix this by checking
nr_active_portsagainst the configuredmax_virtserial_portsbefore callingfetch_active_ports_list().
Quoted 6 lines
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3801Signed-off-by Laurent Vivier <[email protected]>--- hw/char/virtio-serial-bus.c | 4 ++++ 1 file changed, 4 insertions(+)
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
Quoted 21 lines · Laurent Vivier
The migration restore path reads
nr_active_portsfrom the incoming stream and passes it directly tofetch_active_ports_list(), which uses it to size a heap allocation. A crafted migration stream can set this field to a very large value, causing QEMU to attempt a multi-gigabyte allocation and abort.Fix this by checking
nr_active_portsagainst the configuredmax_virtserial_portsbefore callingfetch_active_ports_list().Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3801Signed-off-by Laurent Vivier <[email protected]>--- hw/char/virtio-serial-bus.c | 4 ++++ 1 file changed, 4 insertions(+)hw/char/virtio-serial-bus.c +0
-0
hw/char/virtio-serial-bus.c static int virtio_serial_load_device(VirtIODevice *vdev, QEMUFile *f, · line 813
Quoted 10 lines
hw/char/virtio-serial-bus.c +4
-0@@ -804,6 +804,10 @@ static int virtio_serial_load_device(VirtIODevice *vdev, QEMUFile *f,qemu_get_be32s (f, &nr_active_ports); +if (nr_active_ports > max_nr_ports) { +return -EINVAL ; + } +if (nr_active_ports) { ret =fetch_active_ports_list (f, s, nr_active_ports);if (ret) {
Quoted 6 lines · Laurent Vivier
The migration restore path reads
nr_active_portsfrom the incoming stream and passes it directly tofetch_active_ports_list(), which uses it to size a heap allocation. A crafted migration stream can set this field to a very large value, causing QEMU to attempt a multi-gigabyte allocation and abort.
Quoted 6 lines
Fix this by checking
nr_active_portsagainst the configuredmax_virtserial_portsbefore callingfetch_active_ports_list().Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3801Signed-off-by Laurent Vivier <[email protected]>
Quoted 21 lines
--- hw/char/virtio-serial-bus.c | 4 ++++ 1 file changed, 4 insertions(+)hw/char/virtio-serial-bus.c +4
-0@@ -804,6 +804,10 @@ static int virtio_serial_load_device(VirtIODevice *vdev, QEMUFile *f,qemu_get_be32s (f, &nr_active_ports); +if (nr_active_ports > max_nr_ports) { +return -EINVAL ; + } +if (nr_active_ports) { ret =fetch_active_ports_list (f, s, nr_active_ports);if (ret) {Signature · 1 line
2.54.0
Quoted 10 lines · Laurent Vivier
The migration restore path reads
nr_active_portsfrom the incoming stream and passes it directly tofetch_active_ports_list(), which uses it to size a heap allocation. A crafted migration stream can set this field to a very large value, causing QEMU to attempt a multi-gigabyte allocation and abort.Fix this by checking
nr_active_portsagainst the configuredmax_virtserial_portsbefore callingfetch_active_ports_list().
Can you add a Fixes tag pls?
Quoted 2 lines
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3801
Signed-off-by Laurent Vivier <[email protected]>
to make sure who is merging this me?
Quoted 21 lines
--- hw/char/virtio-serial-bus.c | 4 ++++ 1 file changed, 4 insertions(+)hw/char/virtio-serial-bus.c +4
-0@@ -804,6 +804,10 @@ static int virtio_serial_load_device(VirtIODevice *vdev, QEMUFile *f,qemu_get_be32s (f, &nr_active_ports); +if (nr_active_ports > max_nr_ports) { +return -EINVAL ; + } +if (nr_active_ports) { ret =fetch_active_ports_list (f, s, nr_active_ports);if (ret) {Signature · 1 line
2.54.0
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Laurent Vivier
The migration restore path reads
nr_active_portsfrom the incoming stream and passes it directly tofetch_active_ports_list(), which uses it to size a heap allocation. A crafted migration stream can set this field to a very large value, causing QEMU to attempt a multi-gigabyte allocation and abort.
Quoted 6 lines
Quoted 4 lines
Fix this by checking
nr_active_portsagainst the configuredmax_virtserial_portsbefore callingfetch_active_ports_list().Can you add a Fixes tag pls?
Quoted 5 lines
Quoted 3 lines
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3801
Signed-off-by Laurent Vivier <[email protected]>to make sure who is merging this me?
Yes, please merge it through your tree
Thanks,
Laurent
Quoted 23 lines
Quoted 22 lines
--- hw/char/virtio-serial-bus.c | 4 ++++ 1 file changed, 4 insertions(+)hw/char/virtio-serial-bus.c +4
-0@@ -804,6 +804,10 @@ static int virtio_serial_load_device(VirtIODevice *vdev, QEMUFile *f,qemu_get_be32s (f, &nr_active_ports); +if (nr_active_ports > max_nr_ports) { +return -EINVAL ; + } +if (nr_active_ports) { ret =fetch_active_ports_list (f, s, nr_active_ports);if (ret) {Signature · 1 line
2.54.0