hw/display/vmware_vga: Don't allow guest to trigger long running loop in host
PATCH 1/1 hw/display/vmware_vga: Don't allow guest to trigger long running loop in host
From: Thomas Huth <[email protected]>
The code in the SVGA_CMD_DEFINE_ALPHA_CURSOR handler in vmsvga_fifo_run() basically does:
x = vmsvga_fifo_read(s);
y = vmsvga_fifo_read(s);
args = x * y;
goto badcmd;
...
badcmd:
len -= args;
if (len < 0) {
goto rewind;
}
while (args--) {
vmsvga_fifo_read(s);
}Thus by supplying huge values for x and y that overflow the result of the multiplication, the guest can trigger a long-running loop here that burns the host's CPU cycles.
Add some sanity checks so that this cannot happen anymore.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3782
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4026
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4076
--- hw/display/vmware_vga.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
hw/display/vmware_vga.c +4 -1
@@ -737,6 +737,9 @@ static void vmsvga_fifo_run(struct vmsvga_state_s *s)vmsvga_fifo_read (s); x =vmsvga_fifo_read (s); y =vmsvga_fifo_read (s); +if (x <0 || x >=32768 || y <0 || y >=32768 ) { + goto rewind; + } args = x * y; goto badcmd;case SVGA_CMD_RECT_ROP_FILL :
@@ -776,7 +779,7 @@ static void vmsvga_fifo_run(struct vmsvga_state_s *s)if (len <0 ) { goto rewind; } -while (args--) { +while (args-- >0 ) {vmsvga_fifo_read (s); } printf("%s: Unknown command 0x%02x in SVGA command FIFO\n",
Signature · 1 line
2.55.0
Hi Thomas,
Quoted 41 lines · Thomas Huth
From: Thomas Huth <[email protected]>
The code in the
SVGA_CMD_DEFINE_ALPHA_CURSORhandler invmsvga_fifo_run()basically does:x = vmsvga_fifo_read(s); y = vmsvga_fifo_read(s); args = x * y; goto badcmd; ... badcmd: len -= args; if (len < 0) { goto rewind; } while (args--) { vmsvga_fifo_read(s); }Thus by supplying huge values for x and y that overflow the result of the multiplication, the guest can trigger a long-running loop here that burns the host's CPU cycles.
Add some sanity checks so that this cannot happen anymore.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3782
Reported-by Feifan Qian <[email protected]>Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4026
Reported-by Tristan Madani <[email protected]>Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4076
Reported-by Sunday JiangSigned-off-by Thomas Huth <[email protected]>--- hw/display/vmware_vga.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)hw/display/vmware_vga.c +0
-0
hw/display/vmware_vga.c static void vmsvga_fifo_run(struct vmsvga_state_s *s) · line 740
Quoted 4 lines
hw/display/vmware_vga.c +1
-0@@ -737,6 +737,9 @@ static void vmsvga_fifo_run(struct vmsvga_state_s *s)vmsvga_fifo_read (s); x =vmsvga_fifo_read (s); y =vmsvga_fifo_read (s); +if (x <0 || x >=32768 || y <0 || y >=32768 ) {
Maybe add a self-decribing definition instead of magic number?
#define ALPHA_CURSOR_SAFE_LIMIT 32768 /* Arbitrary limit */
Otherwise LGTM.
Quoted 14 lines
hw/display/vmware_vga.c +3
-1+ goto rewind; + } args = x * y; goto badcmd;case SVGA_CMD_RECT_ROP_FILL :@@ -776,7 +779,7 @@ static void vmsvga_fifo_run(struct vmsvga_state_s *s)if (len <0 ) { goto rewind; } -while (args--) { +while (args-- >0 ) {vmsvga_fifo_read (s); } printf("%s: Unknown command 0x%02x in SVGA command FIFO\n",
Quoted 51 lines · Philippe Mathieu-Daudé
Hi Thomas,
Quoted 41 lines · Thomas Huth
From: Thomas Huth <[email protected]>
The code in the
SVGA_CMD_DEFINE_ALPHA_CURSORhandler invmsvga_fifo_run()basically does:x =
vmsvga_fifo_read(s);
y =vmsvga_fifo_read(s);
args = x * y;
goto badcmd;
...
badcmd:
len -= args;
if (len < 0) {
goto rewind;
}
while (args--) {
vmsvga_fifo_read(s);
}Thus by supplying huge values for x and y that overflow the result of the multiplication, the guest can trigger a long-running loop here that burns the host's CPU cycles.
Add some sanity checks so that this cannot happen anymore.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3782
Reported-by Feifan Qian <[email protected]>Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4026
Reported-by Tristan Madani <[email protected]>Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4076
Reported-by Sunday JiangSigned-off-by Thomas Huth <[email protected]>---
hw/display/vmware_vga.c| 5 ++++-1 file changed, 4 insertions(+), 1 deletion(-)hw/display/vmware_vga.c +0
-0hw/display/vmware_vga.c static void vmsvga_fifo_run(struct vmsvga_state_s *s) · line 740
Quoted 4 lines
hw/display/vmware_vga.c +1
-0@@ -737,6 +737,9 @@ static void vmsvga_fifo_run(struct vmsvga_state_s *s) vmsvga_fifo_read(s); x = vmsvga_fifo_read(s); y = vmsvga_fifo_read(s); + if (x < 0 || x >= 32768 || y < 0 || y >= 32768) {Maybe add a self-decribing definition instead of magic number?
Quoted 3 lines
#define
ALPHA_CURSOR_SAFE_LIMIT32768 /* Arbitrary limit */Otherwise LGTM.
There is already this in the code:
#define SVGA_MAX_WIDTH 2368
#define SVGA_MAX_HEIGHT 1770
Shall I use those? WDYT?
Thomas
Quoted 15 lines
Quoted 14 lines
hw/display/vmware_vga.c +2
-0+ goto rewind; + } args = x * y; goto badcmd;case
SVGA_CMD_RECT_ROP_FILL:hw/display/vmware_vga.c +1
-1@@ -776,7 +779,7 @@ static void vmsvga_fifo_run(struct vmsvga_state_s *s) if (len < 0) { goto rewind; } - while (args--) { + while (args-- > 0) { vmsvga_fifo_read(s); } printf("%s: Unknown command 0x%02x in SVGA command FIFO\n",
Quoted 55 lines · Thomas Huth
Quoted 54 lines · Philippe Mathieu-Daudé
Hi Thomas,
Quoted 41 lines · Thomas Huth
From: Thomas Huth <[email protected]>
The code in the
SVGA_CMD_DEFINE_ALPHA_CURSORhandler invmsvga_fifo_run()basically does:x =
vmsvga_fifo_read(s);
y =vmsvga_fifo_read(s);
args = x * y;
goto badcmd;
...
badcmd:
len -= args;
if (len < 0) {
goto rewind;
}
while (args--) {
vmsvga_fifo_read(s);
}Thus by supplying huge values for x and y that overflow the result of the multiplication, the guest can trigger a long-running loop here that burns the host's CPU cycles.
Add some sanity checks so that this cannot happen anymore.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3782
Reported-by Feifan Qian <[email protected]>Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4026
Reported-by Tristan Madani <[email protected]>Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4076
Reported-by Sunday JiangSigned-off-by Thomas Huth <[email protected]>---
hw/display/vmware_vga.c| 5 ++++-1 file changed, 4 insertions(+), 1 deletion(-)hw/display/vmware_vga.c +0
-0hw/display/vmware_vga.c static void vmsvga_fifo_run(struct vmsvga_state_s · line 741
Quoted 5 lines
hw/display/vmware_vga.c +1
-0@@ -737,6 +737,9 @@ static void vmsvga_fifo_run(struct vmsvga_state_s *s) vmsvga_fifo_read(s); x = vmsvga_fifo_read(s); y = vmsvga_fifo_read(s); + if (x < 0 || x >= 32768 || y < 0 || y >= 32768) {Maybe add a self-decribing definition instead of magic number?
#define
ALPHA_CURSOR_SAFE_LIMIT32768 /* Arbitrary limit */
Quoted 8 lines
Quoted 1 line
Otherwise LGTM.
There is already this in the code:
#define SVGA_MAX_WIDTH 2368
#define SVGA_MAX_HEIGHT 1770Shall I use those? WDYT?
Ah, these look like good candidates :)
Quoted 21 lines
Thomas
Quoted 16 lines
Quoted 15 lines
hw/display/vmware_vga.c +2
-0+ goto rewind; + } args = x * y; goto badcmd;case
SVGA_CMD_RECT_ROP_FILL:hw/display/vmware_vga.c +1
-1@@ -776,7 +779,7 @@ static void vmsvga_fifo_run(struct vmsvga_state_s *s) if (len < 0) { goto rewind; } - while (args--) { + while (args-- > 0) { vmsvga_fifo_read(s); }printf("%s: Unknown command 0x%02x in SVGA command FIFO\n",