display/bochs: fix pcie support (qemu security issue)
cover display/bochs: fix pcie support (qemu security issue)
Just found while investigating
https://bugzilla.redhat.com/show_bug.cgi?id=1707118
Found PCIe extended config space filled with random crap due to allocation being too small (conventional pci config space only).
PCI(e) config space is guest writable. Writes are limited by write mask (which probably is also filled with random stuff), so the guest can only flip enabled bits. But I suspect it still might be exploitable, so rather serious because it might be a host escape for the guest. On the other hand the device is probably not yet in widespread use.
Migitation: use "-device bochs-display" as conventional pci device only.
Note: qemu 4.1 release is planned for tomorrow.
Gerd Hoffmann (1):
display/bochs: fix pcie support
hw/display/bochs-display.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Signature · 1 line
2.18.1
PATCH 1/1 display/bochs: fix pcie support
Set QEMU_PCI_CAP_EXPRESS unconditionally in init(), then clear it in realize() in case the device is not connected to a PCIe bus.
This makes sure the pci config space allocation is big enough, so accessing the PCIe extended config space doesn't overflow the pci config space buffer.
--- hw/display/bochs-display.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
hw/display/bochs-display.c +6 -1
@@ -297,9 +297,10 @@ static void bochs_display_realize(PCIDevice *dev, Error **errp) }if (pci_bus_is_express (pci_get_bus (dev))) { - dev->cap_present |=QEMU_PCI_CAP_EXPRESS ; ret =pcie_endpoint_cap_init (dev,0x80 );assert (ret >0 ); + }else { + dev->cap_present &= ~QEMU_PCI_CAP_EXPRESS ; }memory_region_set_log (&s->vram, true,DIRTY_MEMORY_VGA );
@@ -322,11 +323,15 @@ static void bochs_display_set_big_endian_fb(Object *obj, bool value,static void bochs_display_init (Object *obj) { +PCIDevice *dev =PCI_DEVICE (obj); +/* Expose framebuffer byteorder via QOM */ object_property_add_bool (obj,"big-endian-framebuffer" , bochs_display_get_big_endian_fb, bochs_display_set_big_endian_fb,NULL ); + + dev->cap_present |=QEMU_PCI_CAP_EXPRESS ; }static void bochs_display_exit (PCIDevice *dev)
Signature · 1 line
2.18.1
Re: [Qemu-devel] [PATCH 1/1] display/bochs: fix pcie support
Quoted 11 lines · On Mon, 12 Aug 2019 08:52:21 +0200 Gerd Hoffmann <[email protected]> wrote:
Set
QEMU_PCI_CAP_EXPRESSunconditionally ininit(), then clear it inrealize()in case the device is not connected to a PCIe bus.This makes sure the pci config space allocation is big enough, so accessing the PCIe extended config space doesn't overflow the pci config space buffer.
Signed-off-by Gerd Hoffmann <[email protected]>--- hw/display/bochs-display.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Quoted 32 lines
hw/display/bochs-display.c +6
-1@@ -297,9 +297,10 @@ static void bochs_display_realize(PCIDevice *dev, Error **errp) }if (pci_bus_is_express (pci_get_bus (dev))) { - dev->cap_present |=QEMU_PCI_CAP_EXPRESS ; ret =pcie_endpoint_cap_init (dev,0x80 );assert (ret >0 ); + }else { + dev->cap_present &= ~QEMU_PCI_CAP_EXPRESS ; }memory_region_set_log (&s->vram, true,DIRTY_MEMORY_VGA );@@ -322,11 +323,15 @@ static void bochs_display_set_big_endian_fb(Object *obj, bool value,static void bochs_display_init (Object *obj) { +PCIDevice *dev =PCI_DEVICE (obj); +/* Expose framebuffer byteorder via QOM */ object_property_add_bool (obj,"big-endian-framebuffer" , bochs_display_get_big_endian_fb, bochs_display_set_big_endian_fb,NULL ); + + dev->cap_present |=QEMU_PCI_CAP_EXPRESS ; }static void bochs_display_exit (PCIDevice *dev)
Quoted 8 lines · Gerd Hoffmann
Just found while investigating
https://bugzilla.redhat.com/show_bug.cgi?id=1707118Found PCIe extended config space filled with random crap due to allocation being too small (conventional pci config space only).
PCI(e) config space is guest writable. Writes are limited by write mask (which probably is also filled with random stuff),
Yes, it is also allocated with 256 bytes only.
Quoted 8 lines
so the guest can only flip enabled bits. But I suspect it still might be exploitable, so rather serious because it might be a host escape for the guest. On the other hand the device is probably not yet in widespread use.
Migitation: use "-device bochs-display" as conventional pci device only.
Quoted 8 lines
Note: qemu 4.1 release is planned for tomorrow.
Gerd Hoffmann (1):
display/bochs: fix pcie supporthw/display/bochs-display.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Looks good to me, and no other device seems to have the same issue. We could add an assertion that pci_config_size has not increased after calling pc->realize.
Paolo
Quoted 7 lines · Paolo Bonzini
Quoted 6 lines · Gerd Hoffmann
Just found while investigating
https://bugzilla.redhat.com/show_bug.cgi?id=1707118Found PCIe extended config space filled with random crap due to allocation being too small (conventional pci config space only).
Can you amend this information to the commit description?
<...
Quoted 9 lines
Quoted 2 lines
PCI(e) config space is guest writable. Writes are limited by write mask (which probably is also filled with random stuff),
Yes, it is also allocated with 256 bytes only.
Quoted 4 lines
so the guest can only flip enabled bits. But I suspect it still might be exploitable, so rather serious because it might be a host escape for the guest. On the other hand the device is probably not yet in widespread use.
...>
Quoted 20 lines
Quoted 11 lines
Migitation: use "-device bochs-display" as conventional pci device only.
Note: qemu 4.1 release is planned for tomorrow.
Gerd Hoffmann (1):
display/bochs: fix pcie supporthw/display/bochs-display.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)Looks good to me, and no other device seems to have the same issue. We could add an assertion that
pci_config_sizehas not increased after callingpc->realize.Reviewed-by Paolo Bonzini <[email protected]>Paolo
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Paolo Bonzini
Quoted 6 lines · Gerd Hoffmann
Just found while investigating
https://bugzilla.redhat.com/show_bug.cgi?id=1707118Found PCIe extended config space filled with random crap due to allocation being too small (conventional pci config space only).
Can you amend this information to the commit description?
<...
Quoted 3 lines
Quoted 2 lines
PCI(e) config space is guest writable. Writes are limited by write mask (which probably is also filled with random stuff),
Quoted 8 lines
Quoted 6 lines
Yes, it is also allocated with 256 bytes only.
Quoted 4 lines
so the guest can only flip enabled bits. But I suspect it still might be exploitable, so rather serious because it might be a host escape for the guest. On the other hand the device is probably not yet in widespread use.
...>
I can add to the commit this paragraph of the cover letter, and I think also the 'mitigation' note might as well go in.
I've also put the cc:stable into the commit message.
Updated commit, ready to apply to master if we're OK with it:
thanks
-- PMM
Quoted 25 lines · Peter Maydell
Quoted 24 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Paolo Bonzini
Quoted 6 lines · Gerd Hoffmann
Just found while investigating
https://bugzilla.redhat.com/show_bug.cgi?id=1707118Found PCIe extended config space filled with random crap due to allocation being too small (conventional pci config space only).
Can you amend this information to the commit description?
<...
Quoted 9 lines
Quoted 2 lines
PCI(e) config space is guest writable. Writes are limited by write mask (which probably is also filled with random stuff),
Yes, it is also allocated with 256 bytes only.
Quoted 4 lines
so the guest can only flip enabled bits. But I suspect it still might be exploitable, so rather serious because it might be a host escape for the guest. On the other hand the device is probably not yet in widespread use.
Quoted 4 lines
Quoted 1 line
...>
I can add to the commit this paragraph of the cover letter, and I think also the 'mitigation' note might as well go in.
Yes.
Quoted 6 lines
I've also put the cc:stable into the commit message.
Updated commit, ready to apply to master if we're OK with it:
Thank you!
Quoted 4 lines
thanks
-- PMM
Quoted 27 lines · On Mon, 12 Aug 2019 14:39:53 +0100 Peter Maydell <[email protected]>…
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Paolo Bonzini
Quoted 6 lines · Gerd Hoffmann
Just found while investigating
https://bugzilla.redhat.com/show_bug.cgi?id=1707118Found PCIe extended config space filled with random crap due to allocation being too small (conventional pci config space only).
Can you amend this information to the commit description?
<...
Quoted 3 lines
Quoted 2 lines
PCI(e) config space is guest writable. Writes are limited by write mask (which probably is also filled with random stuff),
Quoted 8 lines
Quoted 6 lines
Yes, it is also allocated with 256 bytes only.
Quoted 4 lines
so the guest can only flip enabled bits. But I suspect it still might be exploitable, so rather serious because it might be a host escape for the guest. On the other hand the device is probably not yet in widespread use.
...>
Quoted 8 lines
I can add to the commit this paragraph of the cover letter, and I think also the 'mitigation' note might as well go in.
I've also put the cc:stable into the commit message.
Updated commit, ready to apply to master if we're OK with it:
Quoting new commit log:
This makes sure the pci config space allocation is big enough, so accessing the PCIe extended config space doesn't overflow the pci config space buffer.
PCI(e) config space is guest writable. Writes are limited bywrite mask (which probably is also filled with random stuff), so the guest can only flip enabled bits. But I suspect it still might be exploitable, so rather serious because it might be a host escape for the guest. On the other hand the device is probably not yet in widespread use.
Mitigation: use "-device bochs-display" as conventional pci device only.
Is it clear to others that this mitigation remark seems to be referencing an alternative configuration constraint to avoid the issue rather than what's actually implemented in this patch? IOW, if we never place the bochs-display device into a PCIe hierarchy, then extended config space is never accessible to the guest anyway, and there is no issue. I think this was meant to be an alternative to the patch but the enforcement of that would happen above QEMU, probably why it was mentioned in the cover letter rather than the original commit log. Thanks,
Alex
Quoted 16 lines · Alex Williamson
Quoting new commit log:
This makes sure the pci config space allocation is big enough, so accessing the PCIe extended config space doesn't overflow the pci config space buffer.
PCI(e) config space is guest writable. Writes are limited bywrite mask (which probably is also filled with random stuff), so the guest can only flip enabled bits. But I suspect it still might be exploitable, so rather serious because it might be a host escape for the guest. On the other hand the device is probably not yet in widespread use.
Mitigation: use "-device bochs-display" as conventional pci device only.
Quoted 9 lines
Is it clear to others that this mitigation remark seems to be referencing an alternative configuration constraint to avoid the issue rather than what's actually implemented in this patch? IOW, if we never place the bochs-display device into a PCIe hierarchy, then extended config space is never accessible to the guest anyway, and there is no issue. I think this was meant to be an alternative to the patch but the enforcement of that would happen above QEMU, probably why it was mentioned in the cover letter rather than the original commit log. Thanks,
Yeah, that's unclear in retrospect. How about:
# (For a QEMU version without this commit, a mitigation for the
# bug is available: use "-device bochs-display" as a conventional pci # device only.)
?
thanks
-- PMM
Quoted 28 lines · On Mon, 12 Aug 2019 16:38:05 +0100 Peter Maydell <[email protected]>…
Quoted 16 lines · Alex Williamson
Quoting new commit log:
This makes sure the pci config space allocation is big enough, so accessing the PCIe extended config space doesn't overflow the pci config space buffer.
PCI(e) config space is guest writable. Writes are limited bywrite mask (which probably is also filled with random stuff), so the guest can only flip enabled bits. But I suspect it still might be exploitable, so rather serious because it might be a host escape for the guest. On the other hand the device is probably not yet in widespread use.
Mitigation: use "-device bochs-display" as conventional pci device only.
Quoted 9 lines
Is it clear to others that this mitigation remark seems to be referencing an alternative configuration constraint to avoid the issue rather than what's actually implemented in this patch? IOW, if we never place the bochs-display device into a PCIe hierarchy, then extended config space is never accessible to the guest anyway, and there is no issue. I think this was meant to be an alternative to the patch but the enforcement of that would happen above QEMU, probably why it was mentioned in the cover letter rather than the original commit log. Thanks,
Quoted 5 lines
Yeah, that's unclear in retrospect. How about:
# (For a QEMU version without this commit, a mitigation for the
# bug is available: use "-device bochs-display" as a conventional pci # device only.)
Yes, better. Thanks,
Alex
Quoted 32 lines · Alex Williamson
Quoted 28 lines · On Mon, 12 Aug 2019 16:38:05 +0100 Peter Maydell <[email protected]>…
Quoted 25 lines · Alex Williamson
Quoting new commit log:
This makes sure the pci config space allocation is big enough, so accessing the PCIe extended config space doesn't overflow the pci config space buffer.
PCI(e) config space is guest writable. Writes are limited bywrite mask (which probably is also filled with random stuff), so the guest can only flip enabled bits. But I suspect it still might be exploitable, so rather serious because it might be a host escape for the guest. On the other hand the device is probably not yet in widespread use.
Mitigation: use "-device bochs-display" as conventional pci device only.
Is it clear to others that this mitigation remark seems to be referencing an alternative configuration constraint to avoid the issue rather than what's actually implemented in this patch? IOW, if we never place the bochs-display device into a PCIe hierarchy, then extended config space is never accessible to the guest anyway, and there is no issue. I think this was meant to be an alternative to the patch but the enforcement of that would happen above QEMU, probably why it was mentioned in the cover letter rather than the original commit log. Thanks,
Quoted 7 lines
Quoted 5 lines
Yeah, that's unclear in retrospect. How about:
# (For a QEMU version without this commit, a mitigation for the
# bug is available: use "-device bochs-display" as a conventional pci # device only.)Yes, better. Thanks,
Cool. Updated commit message now pushed to master.
-- PMM