From patchwork Tue Apr 7 09:22:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 1267314 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EsSCTj0I; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48xMQB0K7Vz9sSG for ; Tue, 7 Apr 2020 19:22:57 +1000 (AEST) Received: from localhost ([::1]:43794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLkRb-0002O5-NQ for incoming@patchwork.ozlabs.org; Tue, 07 Apr 2020 05:22:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33133) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLkR2-0002Km-Ur for qemu-devel@nongnu.org; Tue, 07 Apr 2020 05:22:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jLkQz-0000cX-Vc for qemu-devel@nongnu.org; Tue, 07 Apr 2020 05:22:19 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:46945 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jLkQz-0000be-Px for qemu-devel@nongnu.org; Tue, 07 Apr 2020 05:22:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586251337; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QVjatr9rz5RUyOiLoTZe55id78U+fzRl2nagBZR8ICI=; b=EsSCTj0I1IK4nsEqp0wDvs1UNSNhaX9uh99eBUE8LH3eg5Y6y1eRFKgzRubGq+n7WyJ1Ax oOouS0vKDLCDIhSuHN9i5dNWuKbqfRa7T0D7ahxKrkPigxymLLAoywes8S6jGUrMqcS5Zv jp1fJvpfIWxDm0aq3OtHyfafl1CWnh8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-486-lE_g3bzUMMK10FFXPG2pNA-1; Tue, 07 Apr 2020 05:22:13 -0400 X-MC-Unique: lE_g3bzUMMK10FFXPG2pNA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2ADB913FC; Tue, 7 Apr 2020 09:22:12 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-113-60.ams2.redhat.com [10.36.113.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F5CA9D36A; Tue, 7 Apr 2020 09:22:08 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 0D45617510; Tue, 7 Apr 2020 11:22:07 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 1/4] dsoundaudio: fix never-ending playback loop Date: Tue, 7 Apr 2020 11:22:03 +0200 Message-Id: <20200407092207.6079-2-kraxel@redhat.com> In-Reply-To: <20200407092207.6079-1-kraxel@redhat.com> References: <20200407092207.6079-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Volker_R=C3=BCmelin?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Volker Rümelin 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 Message-id: 20200405075017.9901-1-vr_qemu@t-online.de Signed-off-by: Gerd Hoffmann --- 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; } From patchwork Tue Apr 7 09:22:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 1267316 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=YZaMIwLb; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48xMQS70vRz9sSG for ; Tue, 7 Apr 2020 19:23:12 +1000 (AEST) Received: from localhost ([::1]:43814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLkRq-0002wE-TO for incoming@patchwork.ozlabs.org; Tue, 07 Apr 2020 05:23:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33177) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLkR7-0002OU-Db for qemu-devel@nongnu.org; Tue, 07 Apr 2020 05:22:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jLkR5-0000h5-84 for qemu-devel@nongnu.org; Tue, 07 Apr 2020 05:22:25 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:37856 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jLkR3-0000dt-OK for qemu-devel@nongnu.org; Tue, 07 Apr 2020 05:22:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586251339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NM3v1M7rRjav14bilItKEzeKQnAuvPJUdvO24hXCyXs=; b=YZaMIwLbtEe45EwixOEtwA8DRe6ORnko5SMiBp4WbPH5cBMrN8XOlvAgnNM2p7mZGO63tp kXlw8XLtwfLXzAaJXQTNsMe4gd4ZJhweux0Ni1AeDdV16buCATgTXYNiGuSzQ2djjMcDgt Zqfw6qxbs/Shwz1xFssT4uWHFAFE9VU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-295-z5b4TgFlMpmWaR7RgW4ACw-1; Tue, 07 Apr 2020 05:22:15 -0400 X-MC-Unique: z5b4TgFlMpmWaR7RgW4ACw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8A8378017CE; Tue, 7 Apr 2020 09:22:14 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-113-60.ams2.redhat.com [10.36.113.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CA145C1BB; Tue, 7 Apr 2020 09:22:08 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 15DEF17511; Tue, 7 Apr 2020 11:22:07 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 2/4] dsoundaudio: fix "Could not lock capture buffer" warning Date: Tue, 7 Apr 2020 11:22:04 +0200 Message-Id: <20200407092207.6079-3-kraxel@redhat.com> In-Reply-To: <20200407092207.6079-1-kraxel@redhat.com> References: <20200407092207.6079-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Volker_R=C3=BCmelin?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Volker Rümelin 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 Message-id: 20200405075017.9901-2-vr_qemu@t-online.de Signed-off-by: Gerd Hoffmann --- 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) { From patchwork Tue Apr 7 09:22:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 1267318 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dkDWoDkn; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48xMRw1Lm4z9sSG for ; Tue, 7 Apr 2020 19:24:28 +1000 (AEST) Received: from localhost ([::1]:43844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLkT4-0005nt-2n for incoming@patchwork.ozlabs.org; Tue, 07 Apr 2020 05:24:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33111) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLkQz-0002IK-Jf for qemu-devel@nongnu.org; Tue, 07 Apr 2020 05:22:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jLkQy-0000aU-It for qemu-devel@nongnu.org; Tue, 07 Apr 2020 05:22:17 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:60230 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jLkQy-0000Zi-D0 for qemu-devel@nongnu.org; Tue, 07 Apr 2020 05:22:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586251336; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MScHmYDiUSa4Iqbzbrlr05FKQfpiha1WluPabMnn3LQ=; b=dkDWoDkn+101UksN6Pp6D+sYa+95CGowZkNpKbj7G0etjPiZIkyYPY/CiOFnIyHHoOXl9e BbUWlcAzTRgEzCe34Lza4S7/ozOcBzfg65MfYE/8MibvhHJOGgB5WCtut6jo/X10c9COE6 DaN0Wuy2PeVzmpYIrRAxHhXXdfglVis= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-312-jvTXjx1kPxSlJY7o6sX45g-1; Tue, 07 Apr 2020 05:22:12 -0400 X-MC-Unique: jvTXjx1kPxSlJY7o6sX45g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 34DF313FB; Tue, 7 Apr 2020 09:22:11 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-113-60.ams2.redhat.com [10.36.113.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29A495C28E; Tue, 7 Apr 2020 09:22:09 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 1FD8317516; Tue, 7 Apr 2020 11:22:07 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 3/4] dsoundaudio: dsound_get_buffer_in should honor *size Date: Tue, 7 Apr 2020 11:22:05 +0200 Message-Id: <20200407092207.6079-4-kraxel@redhat.com> In-Reply-To: <20200407092207.6079-1-kraxel@redhat.com> References: <20200407092207.6079-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Volker_R=C3=BCmelin?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Volker Rümelin 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 Message-id: 20200405075017.9901-3-vr_qemu@t-online.de Signed-off-by: Gerd Hoffmann --- 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; From patchwork Tue Apr 7 09:22:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 1267317 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Z6+gb5uk; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48xMRn6Cpnz9sSG for ; Tue, 7 Apr 2020 19:24:21 +1000 (AEST) Received: from localhost ([::1]:43840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLkSx-0005am-Q9 for incoming@patchwork.ozlabs.org; Tue, 07 Apr 2020 05:24:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33199) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLkR9-0002Pt-1l for qemu-devel@nongnu.org; Tue, 07 Apr 2020 05:22:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jLkR7-0000jU-Bu for qemu-devel@nongnu.org; Tue, 07 Apr 2020 05:22:26 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:53379 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jLkR5-0000gu-In for qemu-devel@nongnu.org; Tue, 07 Apr 2020 05:22:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586251342; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k6/5yvLUT9256EPgfuT9fAsQePBTrk+RlVT/7aiGcUA=; b=Z6+gb5ukhGg8XRz+VTfGQaYwfNVWFI1f+5B8yT3kRF6AGiuESE1uzG+DRfAquFTtO7+ajq syOLE0rbb/zJvjyq3rvbEAlK/Ek856s7gTdLmLlH8Oyx4vNlPYelKfBV8bcs7VD4xGZ8an mxORPNk6DgQzf9/8BXxNB3exoy6rwG0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-507-_98NHsfoMW2Eizg5VhY2_A-1; Tue, 07 Apr 2020 05:22:15 -0400 X-MC-Unique: _98NHsfoMW2Eizg5VhY2_A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1E99A1005509; Tue, 7 Apr 2020 09:22:14 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-113-60.ams2.redhat.com [10.36.113.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF4E260BE1; Tue, 7 Apr 2020 09:22:09 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 285F517517; Tue, 7 Apr 2020 11:22:07 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 4/4] ati-vga: Fix checks in ati_2d_blt() to avoid crash Date: Tue, 7 Apr 2020 11:22:06 +0200 Message-Id: <20200407092207.6079-5-kraxel@redhat.com> In-Reply-To: <20200407092207.6079-1-kraxel@redhat.com> References: <20200407092207.6079-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: BALATON Zoltan 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 Signed-off-by: BALATON Zoltan Message-id: 20200406204029.19559747D5D@zero.eik.bme.hu Signed-off-by: Gerd Hoffmann --- 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: