From nobody Sun May 5 03:27:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517831494501328.0580481380845; Mon, 5 Feb 2018 03:51:34 -0800 (PST) Received: from localhost ([::1]:60797 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eifJ3-000525-5T for importer@patchew.org; Mon, 05 Feb 2018 06:51:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54238) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eifHV-000489-0s for qemu-devel@nongnu.org; Mon, 05 Feb 2018 06:49:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eifHQ-0008D8-CM for qemu-devel@nongnu.org; Mon, 05 Feb 2018 06:49:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41188) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eifHQ-0008Ck-7U for qemu-devel@nongnu.org; Mon, 05 Feb 2018 06:49:48 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 687EE61476 for ; Mon, 5 Feb 2018 11:49:47 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F1E46A838; Mon, 5 Feb 2018 11:49:46 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Mon, 5 Feb 2018 11:49:35 +0000 Message-Id: <20180205114938.15784-2-berrange@redhat.com> In-Reply-To: <20180205114938.15784-1-berrange@redhat.com> References: <20180205114938.15784-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 05 Feb 2018 11:49:47 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/4] ui: avoid risk of 32-bit int overflow in VNC buffer check X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laszlo Ersek , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" For very large framebuffers, it is theoretically possible for the result of 'vs->throttle_output_offset * VNC_THROTTLE_OUTPUT_LIMIT_SCALE' to exceed the size of a 32-bit int. For this to happen in practice, the video RAM would have to be set to a large enough value, which is not likely today. None the less we can be paranoid against future growth by using division instead of multiplication when checking the limits. Reported-by: Laszlo Ersek Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laszlo Ersek Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- ui/vnc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 93731accb6..e14e524764 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -1572,8 +1572,8 @@ void vnc_write(VncState *vs, const void *data, size_t= len) * handshake, or from the job thread's VncState clone */ if (vs->throttle_output_offset !=3D 0 && - vs->output.offset > (vs->throttle_output_offset * - VNC_THROTTLE_OUTPUT_LIMIT_SCALE)) { + (vs->output.offset / VNC_THROTTLE_OUTPUT_LIMIT_SCALE) > + vs->throttle_output_offset) { trace_vnc_client_output_limit(vs, vs->ioc, vs->output.offset, vs->throttle_output_offset); vnc_disconnect_start(vs); --=20 2.14.3 From nobody Sun May 5 03:27:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517831731693215.5156675772986; Mon, 5 Feb 2018 03:55:31 -0800 (PST) Received: from localhost ([::1]:32931 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eifMx-0008Jb-0W for importer@patchew.org; Mon, 05 Feb 2018 06:55:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eifHV-00048D-3i for qemu-devel@nongnu.org; Mon, 05 Feb 2018 06:49:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eifHR-0008DU-Ee for qemu-devel@nongnu.org; Mon, 05 Feb 2018 06:49:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40008) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eifHR-0008DJ-9k for qemu-devel@nongnu.org; Mon, 05 Feb 2018 06:49:49 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F06D81DE4 for ; Mon, 5 Feb 2018 11:49:48 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5817620D7; Mon, 5 Feb 2018 11:49:47 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Mon, 5 Feb 2018 11:49:36 +0000 Message-Id: <20180205114938.15784-3-berrange@redhat.com> In-Reply-To: <20180205114938.15784-1-berrange@redhat.com> References: <20180205114938.15784-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 05 Feb 2018 11:49:48 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/4] ui: avoid 'local_err' variable shadowing in VNC SASL auth X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laszlo Ersek , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The start_auth_sasl() method declares a 'Error *local_err' variable in an inner if () {...} scope, which shadows a variable of the same name declared at the start of the method. This is confusing for reviewers and may trigger compiler warnings. Reported-by: Laszlo Ersek Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laszlo Ersek Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- ui/vnc-auth-sasl.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/ui/vnc-auth-sasl.c b/ui/vnc-auth-sasl.c index fbccca8c8a..8ebd0d3d00 100644 --- a/ui/vnc-auth-sasl.c +++ b/ui/vnc-auth-sasl.c @@ -556,7 +556,6 @@ void start_auth_sasl(VncState *vs) /* Inform SASL that we've got an external SSF layer from TLS/x509 */ if (vs->auth =3D=3D VNC_AUTH_VENCRYPT && vs->subauth =3D=3D VNC_AUTH_VENCRYPT_X509SASL) { - Error *local_err =3D NULL; int keysize; sasl_ssf_t ssf; =20 @@ -565,7 +564,6 @@ void start_auth_sasl(VncState *vs) if (keysize < 0) { trace_vnc_auth_fail(vs, vs->auth, "cannot TLS get cipher size", error_get_pretty(local_err)); - error_free(local_err); sasl_dispose(&vs->sasl.conn); vs->sasl.conn =3D NULL; goto authabort; --=20 2.14.3 From nobody Sun May 5 03:27:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517831611497162.89445104912272; Mon, 5 Feb 2018 03:53:31 -0800 (PST) Received: from localhost ([::1]:60919 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eifL0-0006W7-Pk for importer@patchew.org; Mon, 05 Feb 2018 06:53:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54239) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eifHV-00048A-1B for qemu-devel@nongnu.org; Mon, 05 Feb 2018 06:49:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eifHS-0008Df-MU for qemu-devel@nongnu.org; Mon, 05 Feb 2018 06:49:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60612) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eifHS-0008DY-HQ for qemu-devel@nongnu.org; Mon, 05 Feb 2018 06:49:50 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B8DC8285BA for ; Mon, 5 Feb 2018 11:49:49 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB5CC6A838; Mon, 5 Feb 2018 11:49:48 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Mon, 5 Feb 2018 11:49:37 +0000 Message-Id: <20180205114938.15784-4-berrange@redhat.com> In-Reply-To: <20180205114938.15784-1-berrange@redhat.com> References: <20180205114938.15784-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 05 Feb 2018 11:49:49 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/4] ui: check VNC audio frequency limit at time of reading from client X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laszlo Ersek , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The 'vs->as.freq' value is a signed integer, which is read from an unsigned 32-bit int field on the wire. There is thus a risk of overflow on 32-bit platforms. Move the frequency limit checking to be done at time of read before casting to a signed integer. Reported-by: Laszlo Ersek Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laszlo Ersek Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- ui/vnc.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index e14e524764..79ac9eccde 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -982,14 +982,7 @@ static void vnc_update_throttle_offset(VncState *vs) vs->client_width * vs->client_height * vs->client_pf.bytes_per_pix= el; =20 if (vs->audio_cap) { - int freq =3D vs->as.freq; - /* We don't limit freq when reading settings from client, so - * it could be upto MAX_INT in size. 48khz is a sensible - * upper bound for trustworthy clients */ int bps; - if (freq > 48000) { - freq =3D 48000; - } switch (vs->as.fmt) { default: case AUD_FMT_U8: @@ -1005,7 +998,7 @@ static void vnc_update_throttle_offset(VncState *vs) bps =3D 4; break; } - offset +=3D freq * bps * vs->as.nchannels; + offset +=3D vs->as.freq * bps * vs->as.nchannels; } =20 /* Put a floor of 1MB on offset, so that if we have a large pending @@ -2279,6 +2272,7 @@ static int protocol_client_msg(VncState *vs, uint8_t = *data, size_t len) { int i; uint16_t limit; + uint32_t freq; VncDisplay *vd =3D vs->vd; =20 if (data[0] > 3) { @@ -2398,7 +2392,17 @@ static int protocol_client_msg(VncState *vs, uint8_t= *data, size_t len) vnc_client_error(vs); break; } - vs->as.freq =3D read_u32(data, 6); + freq =3D read_u32(data, 6); + /* No official limit for protocol, but 48khz is a sensible + * upper bound for trustworthy clients, and this limit + * protects calculations involving 'vs->as.freq' later. + */ + if (freq > 48000) { + VNC_DEBUG("Invalid audio frequency %u > 48000", freq); + vnc_client_error(vs); + break; + } + vs->as.freq =3D freq; break; default: VNC_DEBUG("Invalid audio message %d\n", read_u8(data, 4)); --=20 2.14.3 From nobody Sun May 5 03:27:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517831612030627.8724065198177; Mon, 5 Feb 2018 03:53:32 -0800 (PST) Received: from localhost ([::1]:60920 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eifL1-0006X0-9T for importer@patchew.org; Mon, 05 Feb 2018 06:53:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54246) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eifHV-00048E-55 for qemu-devel@nongnu.org; Mon, 05 Feb 2018 06:49:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eifHU-0008EA-74 for qemu-devel@nongnu.org; Mon, 05 Feb 2018 06:49:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60618) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eifHU-0008Du-19 for qemu-devel@nongnu.org; Mon, 05 Feb 2018 06:49:52 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EC4328203 for ; Mon, 5 Feb 2018 11:49:51 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18C5D620D7; Mon, 5 Feb 2018 11:49:49 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Mon, 5 Feb 2018 11:49:38 +0000 Message-Id: <20180205114938.15784-5-berrange@redhat.com> In-Reply-To: <20180205114938.15784-1-berrange@redhat.com> References: <20180205114938.15784-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 05 Feb 2018 11:49:51 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 4/4] ui: extend VNC trottling tracing to SASL codepaths X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laszlo Ersek , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In previous commit: commit 6aa22a29187e1908f5db738d27c64a9efc8d0bfa Author: Daniel P. Berrange Date: Mon Dec 18 19:12:27 2017 +0000 ui: add trace events related to VNC client throttling trace points related to unthrottling client I/O were missed from the SASL codepaths. Reported-by: Laszlo Ersek Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laszlo Ersek --- ui/vnc-auth-sasl.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ui/vnc-auth-sasl.c b/ui/vnc-auth-sasl.c index 8ebd0d3d00..3751a777a4 100644 --- a/ui/vnc-auth-sasl.c +++ b/ui/vnc-auth-sasl.c @@ -79,12 +79,23 @@ size_t vnc_client_write_sasl(VncState *vs) =20 vs->sasl.encodedOffset +=3D ret; if (vs->sasl.encodedOffset =3D=3D vs->sasl.encodedLength) { + bool throttled =3D vs->force_update_offset !=3D 0; + size_t offset; if (vs->sasl.encodedRawLength >=3D vs->force_update_offset) { vs->force_update_offset =3D 0; } else { vs->force_update_offset -=3D vs->sasl.encodedRawLength; } + if (throttled && vs->force_update_offset =3D=3D 0) { + trace_vnc_client_unthrottle_forced(vs, vs->ioc); + } + offset =3D vs->output.offset; buffer_advance(&vs->output, vs->sasl.encodedRawLength); + if (offset >=3D vs->throttle_output_offset && + vs->output.offset < vs->throttle_output_offset) { + trace_vnc_client_unthrottle_incremental(vs, vs->ioc, + vs->output.offset); + } vs->sasl.encoded =3D NULL; vs->sasl.encodedOffset =3D vs->sasl.encodedLength =3D 0; } --=20 2.14.3