From nobody Fri Oct 24 22:17:02 2025 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 1518782366702480.3030121456226; Fri, 16 Feb 2018 03:59:26 -0800 (PST) Received: from localhost ([::1]:40628 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emefg-0005Te-SH for importer@patchew.org; Fri, 16 Feb 2018 06:59:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36356) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emeao-0001dM-OE for qemu-devel@nongnu.org; Fri, 16 Feb 2018 06:54:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1emeal-0003fx-Lv for qemu-devel@nongnu.org; Fri, 16 Feb 2018 06:54:18 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38344 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1emeal-0003eT-Dc for qemu-devel@nongnu.org; Fri, 16 Feb 2018 06:54:15 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7CEED8185324 for ; Fri, 16 Feb 2018 11:54:12 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-147.ams2.redhat.com [10.36.116.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2BD912026E04; Fri, 16 Feb 2018 11:54:12 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id E39344F98D; Fri, 16 Feb 2018 12:54:10 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 16 Feb 2018 12:54:09 +0100 Message-Id: <20180216115410.27287-9-kraxel@redhat.com> In-Reply-To: <20180216115410.27287-1-kraxel@redhat.com> References: <20180216115410.27287-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 16 Feb 2018 11:54:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 16 Feb 2018 11:54:12 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kraxel@redhat.com' RCPT:'' 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: 66.187.233.73 Subject: [Qemu-devel] [PULL 8/9] 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: 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" From: Daniel P. Berrang=C3=A9 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 Message-id: 20180205114938.15784-4-berrange@redhat.com Signed-off-by: Gerd Hoffmann --- ui/vnc.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 746293ddfa..a77b568b57 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 @@ -2292,6 +2285,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) { @@ -2411,7 +2405,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.9.3