hw/virtio/virtio-balloon: zero-initialize the virtio_balloon_config struct
PATCH 1/1 hw/virtio/virtio-balloon: zero-initialize the virtio_balloon_config struct
In virtio_balloon_get_config() we initialize a struct virtio_balloon_config which we then copy to guest memory. However, the local variable is not zero initialized. This works OK at the moment because we initialize all the fields in it; however an upcoming kernel header change will add some new fields. If we don't zero out the whole struct then we will start leaking a small amount of the contents of QEMU's stack to the guest as soon as we update linux-headers/ to a set of headers that includes the new fields.
---
It looks like none of the other virtio devices have this bug. Tested with "make check" only.
As the commit message notes, must go in before our next headers update.
--- hw/virtio/virtio-balloon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-balloon.c +1 -1
@@ -311,7 +311,7 @@ out:static void virtio_balloon_get_config (VirtIODevice *vdev,uint8_t *config_data) {VirtIOBalloon *dev =VIRTIO_BALLOON (vdev); -struct virtio_balloon_config config; +struct virtio_balloon_config config = {}; config.num_pages =cpu_to_le32 (dev->num_pages); config.actual =cpu_to_le32 (dev->actual);
Signature · 1 line
2.20.1
Quoted 10 lines · Peter Maydell
In
virtio_balloon_get_config()we initialize a structvirtio_balloon_configwhich we then copy to guest memory. However, the local variable is not zero initialized. This works OK at the moment because we initialize all the fields in it; however an upcoming kernel header change will add some new fields. If we don't zero out the whole struct then we will start leaking a small amount of the contents of QEMU's stack to the guest as soon as we update linux-headers/ to a set of headers that includes the new fields.Signed-off-by Peter Maydell <[email protected]>
Quoted 4 lines
---
It looks like none of the other virtio devices have this bug. Tested with "make check" only.
As the commit message notes, must go in before our next headers update.
Want me to merge it? Or you can pick it up directly if you like to make sure that happens.
Quoted 19 lines
--- hw/virtio/virtio-balloon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/virtio/virtio-balloon.c +1
-1@@ -311,7 +311,7 @@ out:static void virtio_balloon_get_config (VirtIODevice *vdev,uint8_t *config_data) {VirtIOBalloon *dev =VIRTIO_BALLOON (vdev); -struct virtio_balloon_config config; +struct virtio_balloon_config config = {}; config.num_pages =cpu_to_le32 (dev->num_pages); config.actual =cpu_to_le32 (dev->actual);Signature · 1 line
2.20.1
Quoted 8 lines · Peter Maydell
In
virtio_balloon_get_config()we initialize a structvirtio_balloon_configwhich we then copy to guest memory. However, the local variable is not zero initialized. This works OK at the moment because we initialize all the fields in it; however an upcoming kernel header change will add some new fields. If we don't zero out the whole struct then we will start leaking a small amount of the contents of QEMU's stack to the guest as soon as we update linux-headers/ to a set of headers that includes the new fields.
Is it worth Cc'ing qemu-stable@?
Quoted 2 lines
Signed-off-by Peter Maydell <[email protected]>
Quoted 22 lines
---
It looks like none of the other virtio devices have this bug. Tested with "make check" only.
As the commit message notes, must go in before our next headers update.--- hw/virtio/virtio-balloon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/virtio/virtio-balloon.c +1
-1@@ -311,7 +311,7 @@ out:static void virtio_balloon_get_config (VirtIODevice *vdev,uint8_t *config_data) {VirtIOBalloon *dev =VIRTIO_BALLOON (vdev); -struct virtio_balloon_config config; +struct virtio_balloon_config config = {}; config.num_pages =cpu_to_le32 (dev->num_pages); config.actual =cpu_to_le32 (dev->actual);
Quoted 11 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Peter Maydell
In
virtio_balloon_get_config()we initialize a structvirtio_balloon_configwhich we then copy to guest memory. However, the local variable is not zero initialized. This works OK at the moment because we initialize all the fields in it; however an upcoming kernel header change will add some new fields. If we don't zero out the whole struct then we will start leaking a small amount of the contents of QEMU's stack to the guest as soon as we update linux-headers/ to a set of headers that includes the new fields.
Quoted 1 line
Is it worth Cc'ing qemu-stable@?
Good idea, that will avoid possible future problems if we backport a headers change to stable.
I'll apply this to master directly.
thanks
-- PMM