Commit 0b3a666499 for qemu.org

commit 0b3a66649912c1c8e0394d0ef8778c0ad314820c
Author: Peter Maydell <peter.maydell@linaro.org>
Date:   Tue Nov 24 09:57:17 2026 +0000

    hw/display/vmware_vga: Check for bogus FIFO_STOP and FIFO_NEXT values

    The guest should never program the FIFO head and tail offsets (in the
    FIFO_NEXT and FIFO_STOP registers) to something outside the bounds of
    the memory area it has defined as for the FIFO via the FIFO_MIN and
    FIFO_MAX registers. If it does that, return a zero fifo length as
    we do for various other bad values.

    Bad values here won't cause any serious problems as we were rejecting
    offsets that would cause us to index outside the s->fifo[] array; but
    they're better rejected. For safety's sake we add an assertion on
    the fifo cursor before we read it.

    Cc: qemu-stable@nongnu.org
    Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
    Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
    Message-ID: <20261124095719.4126146-3-peter.maydell@linaro.org>
    [PMD: Cover whole range in assert()]
    Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>

diff --git a/hw/display/vmware_vga.c b/hw/display/vmware_vga.c
index f728968731..353cef408d 100644
--- a/hw/display/vmware_vga.c
+++ b/hw/display/vmware_vga.c
@@ -581,8 +581,10 @@ static inline int vmsvga_fifo_length(struct vmsvga_state_s *s)
     }
     if (s->fifo_max > SVGA_FIFO_SIZE ||
         s->fifo_min >= SVGA_FIFO_SIZE ||
-        s->fifo_stop >= SVGA_FIFO_SIZE ||
-        s->fifo_next >= SVGA_FIFO_SIZE) {
+        s->fifo_stop < s->fifo_min ||
+        s->fifo_stop >= s->fifo_max ||
+        s->fifo_next < s->fifo_min ||
+        s->fifo_next >= s->fifo_max) {
         return 0;
     }
     if (s->fifo_max < s->fifo_min + 10 * KiB) {
@@ -598,7 +600,10 @@ static inline int vmsvga_fifo_length(struct vmsvga_state_s *s)

 static inline uint32_t vmsvga_fifo_read_raw(struct vmsvga_state_s *s)
 {
-    uint32_t cmd = s->fifo[s->fifo_stop >> 2];
+    uint32_t cmd;
+
+    assert(s->fifo_stop < SVGA_FIFO_SIZE);
+    cmd = s->fifo[s->fifo_stop >> 2];

     s->fifo_stop += 4;
     if (s->fifo_stop >= s->fifo_max) {