The address of a packed member is not packed, which may cause accesses
to unaligned pointers. Avoid this by reading the packed value before
passing it to another function.
Cc: Jason Wang <jasowang@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
Cc: qemu-stable@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
Resubmission of the patch at https://patchwork.kernel.org/patch/10160229/
The vhost part has since been fixed independently (commit
69aff03064, "vhost-user: fix misaligned access to payload",
2018-01-18).
hw/char/virtio-serial-bus.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index d2dd8ab502..04e3ebe352 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -667,9 +667,9 @@ static void virtio_serial_save_device(VirtIODevice *vdev, QEMUFile *f)
/* The config space (ignored on the far end in current versions) */
get_config(vdev, (uint8_t *)&config);
- qemu_put_be16s(f, &config.cols);
- qemu_put_be16s(f, &config.rows);
- qemu_put_be32s(f, &config.max_nr_ports);
+ qemu_put_be16(f, config.cols);
+ qemu_put_be16(f, config.rows);
+ qemu_put_be32(f, config.max_nr_ports);
/* The ports map */
max_nr_ports = s->serial.max_virtserial_ports;
--
2.17.1
On 9/26/18 11:20 PM, Paolo Bonzini wrote: > The address of a packed member is not packed, which may cause accesses > to unaligned pointers. Avoid this by reading the packed value before > passing it to another function. > > Cc: Jason Wang <jasowang@redhat.com> > Cc: Peter Maydell <peter.maydell@linaro.org> > Reviewed-by: Eric Blake <eblake@redhat.com> > Cc: qemu-stable@nongnu.org > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> > --- > Resubmission of the patch at https://patchwork.kernel.org/patch/10160229/ > The vhost part has since been fixed independently (commit > 69aff03064, "vhost-user: fix misaligned access to payload", > 2018-01-18). > > hw/char/virtio-serial-bus.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c > index d2dd8ab502..04e3ebe352 100644 > --- a/hw/char/virtio-serial-bus.c > +++ b/hw/char/virtio-serial-bus.c > @@ -667,9 +667,9 @@ static void virtio_serial_save_device(VirtIODevice *vdev, QEMUFile *f) > > /* The config space (ignored on the far end in current versions) */ > get_config(vdev, (uint8_t *)&config); > - qemu_put_be16s(f, &config.cols); > - qemu_put_be16s(f, &config.rows); > - qemu_put_be32s(f, &config.max_nr_ports); > + qemu_put_be16(f, config.cols); > + qemu_put_be16(f, config.rows); > + qemu_put_be32(f, config.max_nr_ports); Clever. Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > > /* The ports map */ > max_nr_ports = s->serial.max_virtserial_ports; >
On 2018年09月27日 05:20, Paolo Bonzini wrote: > The address of a packed member is not packed, which may cause accesses > to unaligned pointers. Avoid this by reading the packed value before > passing it to another function. > > Cc: Jason Wang <jasowang@redhat.com> > Cc: Peter Maydell <peter.maydell@linaro.org> > Reviewed-by: Eric Blake <eblake@redhat.com> > Cc: qemu-stable@nongnu.org > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> > --- > Resubmission of the patch at https://patchwork.kernel.org/patch/10160229/ > The vhost part has since been fixed independently (commit > 69aff03064, "vhost-user: fix misaligned access to payload", > 2018-01-18). > > hw/char/virtio-serial-bus.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c > index d2dd8ab502..04e3ebe352 100644 > --- a/hw/char/virtio-serial-bus.c > +++ b/hw/char/virtio-serial-bus.c > @@ -667,9 +667,9 @@ static void virtio_serial_save_device(VirtIODevice *vdev, QEMUFile *f) > > /* The config space (ignored on the far end in current versions) */ > get_config(vdev, (uint8_t *)&config); > - qemu_put_be16s(f, &config.cols); > - qemu_put_be16s(f, &config.rows); > - qemu_put_be32s(f, &config.max_nr_ports); > + qemu_put_be16(f, config.cols); > + qemu_put_be16(f, config.rows); > + qemu_put_be32(f, config.max_nr_ports); > > /* The ports map */ > max_nr_ports = s->serial.max_virtserial_ports; Acked-by: Jason Wang <jasowang@redhat.com>
© 2016 - 2024 Red Hat, Inc.