qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PULL 0/4] Fixes 20200407 patches
@ 2020-04-07  9:22 Gerd Hoffmann
  2020-04-07  9:22 ` [PULL 1/4] dsoundaudio: fix never-ending playback loop Gerd Hoffmann
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Gerd Hoffmann @ 2020-04-07  9:22 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

The following changes since commit 146aa0f104bb3bf88e43c4082a0bfc4bbda4fbd8:

  Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging (2020-04-03 15:30:11 +0100)

are available in the Git repository at:

  git://git.kraxel.org/qemu tags/fixes-20200407-pull-request

for you to fetch changes up to ac2071c3791b67fc7af78b8ceb320c01ca1b5df7:

  ati-vga: Fix checks in ati_2d_blt() to avoid crash (2020-04-07 09:25:23 +0200)

----------------------------------------------------------------
fixes for 5.0:
- audio: windows (dsound) fixes.
- vga: ati blitter sanity check fixes.

----------------------------------------------------------------

BALATON Zoltan (1):
  ati-vga: Fix checks in ati_2d_blt() to avoid crash

Volker Rümelin (3):
  dsoundaudio: fix never-ending playback loop
  dsoundaudio: fix "Could not lock capture buffer" warning
  dsoundaudio: dsound_get_buffer_in should honor *size

 audio/audio.c       | 12 +++++-------
 audio/dsoundaudio.c |  9 +++++++--
 hw/display/ati_2d.c | 37 ++++++++++++++++++++++++++-----------
 3 files changed, 38 insertions(+), 20 deletions(-)

-- 
2.18.2



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PULL 1/4] dsoundaudio: fix never-ending playback loop
  2020-04-07  9:22 [PULL 0/4] Fixes 20200407 patches Gerd Hoffmann
@ 2020-04-07  9:22 ` Gerd Hoffmann
  2020-04-07  9:22 ` [PULL 2/4] dsoundaudio: fix "Could not lock capture buffer" warning Gerd Hoffmann
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Gerd Hoffmann @ 2020-04-07  9:22 UTC (permalink / raw)
  To: qemu-devel; +Cc: Volker Rümelin, Gerd Hoffmann

From: Volker Rümelin <vr_qemu@t-online.de>

Currently the DirectSound backend fails to stop audio playback
in dsound_enable_out(). To detect a lost buffer condition
dsound_get_status_out() incorrectly uses the error code
DSERR_BUFFERLOST instead of flag DSBSTATUS_BUFFERLOST as a mask
and returns with an error. As a result dsound_enable_out()
returns early and doesn't stop playback.

To reproduce the bug start qemu on a Windows host with
-soundhw pcspk -audiodev dsound,id=audio0. On the guest
FreeDOS 1.2 command line enter beep. The image Day 1 - F-Bird
from the QEMU Advent Calendar 2018 shows the bug as well.

Buglink: https://bugs.launchpad.net/qemu/+bug/1699628
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-id: 20200405075017.9901-1-vr_qemu@t-online.de
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 audio/dsoundaudio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c
index bd57082a8dce..9e621c889954 100644
--- a/audio/dsoundaudio.c
+++ b/audio/dsoundaudio.c
@@ -279,7 +279,7 @@ static int dsound_get_status_out (LPDIRECTSOUNDBUFFER dsb, DWORD *statusp,
         return -1;
     }
 
-    if (*statusp & DSERR_BUFFERLOST) {
+    if (*statusp & DSBSTATUS_BUFFERLOST) {
         dsound_restore_out(dsb, s);
         return -1;
     }
-- 
2.18.2



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PULL 2/4] dsoundaudio: fix "Could not lock capture buffer" warning
  2020-04-07  9:22 [PULL 0/4] Fixes 20200407 patches Gerd Hoffmann
  2020-04-07  9:22 ` [PULL 1/4] dsoundaudio: fix never-ending playback loop Gerd Hoffmann
@ 2020-04-07  9:22 ` Gerd Hoffmann
  2020-04-07  9:22 ` [PULL 3/4] dsoundaudio: dsound_get_buffer_in should honor *size Gerd Hoffmann
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Gerd Hoffmann @ 2020-04-07  9:22 UTC (permalink / raw)
  To: qemu-devel; +Cc: Volker Rümelin, Gerd Hoffmann

From: Volker Rümelin <vr_qemu@t-online.de>

IDirectSoundCaptureBuffer_Lock() fails on Windows when called
with len = 0. Return early from dsound_get_buffer_in() in this
case.

To reproduce the warning start a linux guest. In the guest
start Audacity and you will see a lot of "Could not lock
capture buffer" warnings.

Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-id: 20200405075017.9901-2-vr_qemu@t-online.de
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 audio/dsoundaudio.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c
index 9e621c889954..a08d519cae6a 100644
--- a/audio/dsoundaudio.c
+++ b/audio/dsoundaudio.c
@@ -542,6 +542,11 @@ static void *dsound_get_buffer_in(HWVoiceIn *hw, size_t *size)
     req_size = audio_ring_dist(cpos, hw->pos_emul, hw->size_emul);
     req_size = MIN(req_size, hw->size_emul - hw->pos_emul);
 
+    if (req_size == 0) {
+        *size = 0;
+        return NULL;
+    }
+
     err = dsound_lock_in(dscb, &hw->info, hw->pos_emul, req_size, &ret, NULL,
                          &act_size, NULL, false, ds->s);
     if (err) {
-- 
2.18.2



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PULL 3/4] dsoundaudio: dsound_get_buffer_in should honor *size
  2020-04-07  9:22 [PULL 0/4] Fixes 20200407 patches Gerd Hoffmann
  2020-04-07  9:22 ` [PULL 1/4] dsoundaudio: fix never-ending playback loop Gerd Hoffmann
  2020-04-07  9:22 ` [PULL 2/4] dsoundaudio: fix "Could not lock capture buffer" warning Gerd Hoffmann
@ 2020-04-07  9:22 ` Gerd Hoffmann
  2020-04-07  9:22 ` [PULL 4/4] ati-vga: Fix checks in ati_2d_blt() to avoid crash Gerd Hoffmann
  2020-04-07 14:09 ` [PULL 0/4] Fixes 20200407 patches Peter Maydell
  4 siblings, 0 replies; 6+ messages in thread
From: Gerd Hoffmann @ 2020-04-07  9:22 UTC (permalink / raw)
  To: qemu-devel; +Cc: Volker Rümelin, Gerd Hoffmann

From: Volker Rümelin <vr_qemu@t-online.de>

This patch prevents an underflow of variable samples in function
audio_pcm_hw_run_in(). See commit 599eac4e5a "audio:
audio_generic_get_buffer_in should honor *size". This time the
while loop in audio_pcm_hw_run_in() will terminate nevertheless,
because it seems the recording stream in Windows is always rate
limited.

Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-id: 20200405075017.9901-3-vr_qemu@t-online.de
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 audio/audio.c       | 12 +++++-------
 audio/dsoundaudio.c |  2 +-
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/audio/audio.c b/audio/audio.c
index 9ac9a20c41ba..7a9e6803558b 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1491,16 +1491,14 @@ size_t audio_generic_write(HWVoiceOut *hw, void *buf, size_t size)
 
 size_t audio_generic_read(HWVoiceIn *hw, void *buf, size_t size)
 {
-    size_t src_size, copy_size;
-    void *src = hw->pcm_ops->get_buffer_in(hw, &src_size);
-    copy_size = MIN(size, src_size);
+    void *src = hw->pcm_ops->get_buffer_in(hw, &size);
 
-    memcpy(buf, src, copy_size);
-    hw->pcm_ops->put_buffer_in(hw, src, copy_size);
-    return copy_size;
+    memcpy(buf, src, size);
+    hw->pcm_ops->put_buffer_in(hw, src, size);
+
+    return size;
 }
 
-
 static int audio_driver_init(AudioState *s, struct audio_driver *drv,
                              bool msg, Audiodev *dev)
 {
diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c
index a08d519cae6a..4cdf19ab6799 100644
--- a/audio/dsoundaudio.c
+++ b/audio/dsoundaudio.c
@@ -540,7 +540,7 @@ static void *dsound_get_buffer_in(HWVoiceIn *hw, size_t *size)
     }
 
     req_size = audio_ring_dist(cpos, hw->pos_emul, hw->size_emul);
-    req_size = MIN(req_size, hw->size_emul - hw->pos_emul);
+    req_size = MIN(*size, MIN(req_size, hw->size_emul - hw->pos_emul));
 
     if (req_size == 0) {
         *size = 0;
-- 
2.18.2



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PULL 4/4] ati-vga: Fix checks in ati_2d_blt() to avoid crash
  2020-04-07  9:22 [PULL 0/4] Fixes 20200407 patches Gerd Hoffmann
                   ` (2 preceding siblings ...)
  2020-04-07  9:22 ` [PULL 3/4] dsoundaudio: dsound_get_buffer_in should honor *size Gerd Hoffmann
@ 2020-04-07  9:22 ` Gerd Hoffmann
  2020-04-07 14:09 ` [PULL 0/4] Fixes 20200407 patches Peter Maydell
  4 siblings, 0 replies; 6+ messages in thread
From: Gerd Hoffmann @ 2020-04-07  9:22 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

From: BALATON Zoltan <balaton@eik.bme.hu>

In some corner cases (that never happen during normal operation but a
malicious guest could program wrong values) pixman functions were
called with parameters that result in a crash. Fix this and add more
checks to disallow such cases.

Reported-by: Ziming Zhang <ezrakiez@gmail.com>
Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Message-id: 20200406204029.19559747D5D@zero.eik.bme.hu
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/display/ati_2d.c | 37 ++++++++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/hw/display/ati_2d.c b/hw/display/ati_2d.c
index 42e82311eb44..23a8ae0cd8ce 100644
--- a/hw/display/ati_2d.c
+++ b/hw/display/ati_2d.c
@@ -53,12 +53,20 @@ void ati_2d_blt(ATIVGAState *s)
             s->vga.vbe_start_addr, surface_data(ds), surface_stride(ds),
             surface_bits_per_pixel(ds),
             (s->regs.dp_mix & GMC_ROP3_MASK) >> 16);
-    int dst_x = (s->regs.dp_cntl & DST_X_LEFT_TO_RIGHT ?
-                 s->regs.dst_x : s->regs.dst_x + 1 - s->regs.dst_width);
-    int dst_y = (s->regs.dp_cntl & DST_Y_TOP_TO_BOTTOM ?
-                 s->regs.dst_y : s->regs.dst_y + 1 - s->regs.dst_height);
+    unsigned dst_x = (s->regs.dp_cntl & DST_X_LEFT_TO_RIGHT ?
+                      s->regs.dst_x : s->regs.dst_x + 1 - s->regs.dst_width);
+    unsigned dst_y = (s->regs.dp_cntl & DST_Y_TOP_TO_BOTTOM ?
+                      s->regs.dst_y : s->regs.dst_y + 1 - s->regs.dst_height);
     int bpp = ati_bpp_from_datatype(s);
+    if (!bpp) {
+        qemu_log_mask(LOG_GUEST_ERROR, "Invalid bpp\n");
+        return;
+    }
     int dst_stride = DEFAULT_CNTL ? s->regs.dst_pitch : s->regs.default_pitch;
+    if (!dst_stride) {
+        qemu_log_mask(LOG_GUEST_ERROR, "Zero dest pitch\n");
+        return;
+    }
     uint8_t *dst_bits = s->vga.vram_ptr + (DEFAULT_CNTL ?
                         s->regs.dst_offset : s->regs.default_offset);
 
@@ -82,12 +90,16 @@ void ati_2d_blt(ATIVGAState *s)
     switch (s->regs.dp_mix & GMC_ROP3_MASK) {
     case ROP3_SRCCOPY:
     {
-        int src_x = (s->regs.dp_cntl & DST_X_LEFT_TO_RIGHT ?
-                     s->regs.src_x : s->regs.src_x + 1 - s->regs.dst_width);
-        int src_y = (s->regs.dp_cntl & DST_Y_TOP_TO_BOTTOM ?
-                     s->regs.src_y : s->regs.src_y + 1 - s->regs.dst_height);
+        unsigned src_x = (s->regs.dp_cntl & DST_X_LEFT_TO_RIGHT ?
+                       s->regs.src_x : s->regs.src_x + 1 - s->regs.dst_width);
+        unsigned src_y = (s->regs.dp_cntl & DST_Y_TOP_TO_BOTTOM ?
+                       s->regs.src_y : s->regs.src_y + 1 - s->regs.dst_height);
         int src_stride = DEFAULT_CNTL ?
                          s->regs.src_pitch : s->regs.default_pitch;
+        if (!src_stride) {
+            qemu_log_mask(LOG_GUEST_ERROR, "Zero source pitch\n");
+            return;
+        }
         uint8_t *src_bits = s->vga.vram_ptr + (DEFAULT_CNTL ?
                             s->regs.src_offset : s->regs.default_offset);
 
@@ -137,8 +149,10 @@ void ati_2d_blt(ATIVGAState *s)
                                     dst_y * surface_stride(ds),
                                     s->regs.dst_height * surface_stride(ds));
         }
-        s->regs.dst_x += s->regs.dst_width;
-        s->regs.dst_y += s->regs.dst_height;
+        s->regs.dst_x = (s->regs.dp_cntl & DST_X_LEFT_TO_RIGHT ?
+                         dst_x + s->regs.dst_width : dst_x);
+        s->regs.dst_y = (s->regs.dp_cntl & DST_Y_TOP_TO_BOTTOM ?
+                         dst_y + s->regs.dst_height : dst_y);
         break;
     }
     case ROP3_PATCOPY:
@@ -179,7 +193,8 @@ void ati_2d_blt(ATIVGAState *s)
                                     dst_y * surface_stride(ds),
                                     s->regs.dst_height * surface_stride(ds));
         }
-        s->regs.dst_y += s->regs.dst_height;
+        s->regs.dst_y = (s->regs.dp_cntl & DST_Y_TOP_TO_BOTTOM ?
+                         dst_y + s->regs.dst_height : dst_y);
         break;
     }
     default:
-- 
2.18.2



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PULL 0/4] Fixes 20200407 patches
  2020-04-07  9:22 [PULL 0/4] Fixes 20200407 patches Gerd Hoffmann
                   ` (3 preceding siblings ...)
  2020-04-07  9:22 ` [PULL 4/4] ati-vga: Fix checks in ati_2d_blt() to avoid crash Gerd Hoffmann
@ 2020-04-07 14:09 ` Peter Maydell
  4 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2020-04-07 14:09 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: QEMU Developers

On Tue, 7 Apr 2020 at 10:23, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> The following changes since commit 146aa0f104bb3bf88e43c4082a0bfc4bbda4fbd8:
>
>   Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging (2020-04-03 15:30:11 +0100)
>
> are available in the Git repository at:
>
>   git://git.kraxel.org/qemu tags/fixes-20200407-pull-request
>
> for you to fetch changes up to ac2071c3791b67fc7af78b8ceb320c01ca1b5df7:
>
>   ati-vga: Fix checks in ati_2d_blt() to avoid crash (2020-04-07 09:25:23 +0200)
>
> ----------------------------------------------------------------
> fixes for 5.0:
> - audio: windows (dsound) fixes.
> - vga: ati blitter sanity check fixes.


Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/5.0
for any user-visible changes.

-- PMM


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-04-07 14:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-07  9:22 [PULL 0/4] Fixes 20200407 patches Gerd Hoffmann
2020-04-07  9:22 ` [PULL 1/4] dsoundaudio: fix never-ending playback loop Gerd Hoffmann
2020-04-07  9:22 ` [PULL 2/4] dsoundaudio: fix "Could not lock capture buffer" warning Gerd Hoffmann
2020-04-07  9:22 ` [PULL 3/4] dsoundaudio: dsound_get_buffer_in should honor *size Gerd Hoffmann
2020-04-07  9:22 ` [PULL 4/4] ati-vga: Fix checks in ati_2d_blt() to avoid crash Gerd Hoffmann
2020-04-07 14:09 ` [PULL 0/4] Fixes 20200407 patches Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).