From nobody Sat Oct 4 21:56:36 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; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1546528651507296.05824292153284; Thu, 3 Jan 2019 07:17:31 -0800 (PST) Received: from localhost ([127.0.0.1]:55266 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gf4kU-0002as-CT for importer@patchew.org; Thu, 03 Jan 2019 10:17:30 -0500 Received: from eggs.gnu.org ([208.118.235.92]:34408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gf22C-0005FW-F2 for qemu-devel@nongnu.org; Thu, 03 Jan 2019 07:23:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gf229-0004CX-9a for qemu-devel@nongnu.org; Thu, 03 Jan 2019 07:23:36 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:33389) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gf228-0004BD-Q5 for qemu-devel@nongnu.org; Thu, 03 Jan 2019 07:23:33 -0500 Received: by mail-wm1-x341.google.com with SMTP id r24so34706911wmh.0 for ; Thu, 03 Jan 2019 04:23:32 -0800 (PST) Received: from bark.daynix ([141.226.163.173]) by smtp.gmail.com with ESMTPSA id t76sm72325798wme.33.2019.01.03.04.23.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Jan 2019 04:23:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4y8IX/PTbaSNnmt6YfKxNBI0mWnpg3gIlKzBnlx4MoI=; b=yTnSZA4pMyI9ms3gKi137P1tjSwq2XepoEYZgDvgKQ3MTs7lHkIXN6W/WyP8LuCHsA B++kbOEsoRJZrCO4HjTLpvcNY2V+cx7oGTps2M9mPuUk03KfbTMwA+K3MVFFwivrttTQ BYYcFPOhuKHRyb0fdzGFp+FkC5qfl/Ycm8g3QV5eobRW31vZmkgTmE+mL3ob7ElRno/x 6xcenwloqod/1/+2EELVDMGGxYdnBWT2mYV5b/7gDXy4cIOIhtVwm5juqlG3nrdT82If xlgjwuecQj+SLhLZlfML+rm8YF3MMMt9EXE5AX6DwAXDjQJ6Wr/AphPc5JlolaEBADdW 4sSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4y8IX/PTbaSNnmt6YfKxNBI0mWnpg3gIlKzBnlx4MoI=; b=bhS6CaSx1gN6alIkg/K0FShSLvP4RIgkkeRsNod7a6ATtHcKcknpIQfN6kdnRV6dSD YPDT8JggiBiTwnbDntYvUs0zGlsXtQpGUGwVwbSDk5S5JjZ272K4FE5cC/KR8RtBQSkl xooDulOKYYQsaIC0J5UdpsRtFf3WOD1yby9vAncByroiqmTxDeFFIPX7vayfR/miYYpR 3QDHWDe4ogo/qZnIlNJVwwtDkH6R1P8YHFgAnsg99jlnGsNVYZuccPhsiXKPwAWI2Sl5 B7PCWgy3MKS4J1fPlmumbzvgfHtJCb29c17AOwtbjxghB3tcs95ubhxGDF2QJPlS9NdZ jBZw== X-Gm-Message-State: AA+aEWaE0vtUOLaX2zn3qUaNhAEeK0nsryGb2yRLcQIXIRow909DAZUu Hqbc8DHgElyh1xuphA/HcNUlsg/jYv24rg== X-Google-Smtp-Source: ALg8bN7OEIyGJI1OPbILL7GzuR0ytmev+qnPdCGs2uknqhQ7mnWOcladcv4lIKln9xFbTOGqIcKTlg== X-Received: by 2002:a1c:aad2:: with SMTP id t201mr36668166wme.148.1546518210446; Thu, 03 Jan 2019 04:23:30 -0800 (PST) From: Basil Salman To: qemu-devel@nongnu.org, Michael Roth Date: Thu, 3 Jan 2019 14:23:20 +0200 Message-Id: <20190103122323.1273034-2-basil@daynix.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190103122323.1273034-1-basil@daynix.com> References: <20190103122323.1273034-1-basil@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 X-Mailman-Approved-At: Thu, 03 Jan 2019 10:10:24 -0500 Subject: [Qemu-devel] [PATCH 1/4] qga-win: prevent crash when executing guest-file-read with large count 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: Yan Vugenfirer , Bishara AbuHattoum Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" BZ: #1594054 guest-file-read command is currently implelmented to read from a file handle count number of bytes. when executed with a very large count nu= mber qemu-ga crashes. after some digging turns out that qemu-ga crashes after trying to allocate a buffer large enough to save the data read in it, the buffer was allocated= using g_malloc0 which is not fail safe, and results a crash in case of failure. g_malloc0 was replaced with g_try_malloc0() which returns NULL on failure, A check was added for that case in order to prevent qemu-ga from crashing and to send a response to the qemu-ga client accordingly. Signed-off-by: Basil Salman --- qga/commands-win32.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 62e1b51dfe..4260faa573 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -345,7 +345,13 @@ GuestFileRead *qmp_guest_file_read(int64_t handle, boo= l has_count, } =20 fh =3D gfh->fh; - buf =3D g_malloc0(count+1); + buf =3D g_try_malloc0(count + 1); + if (!buf) { + error_setg(errp, + "failed to allocate sufficient memory" + "to complete the requested service"); + return read_data; + } is_ok =3D ReadFile(fh, buf, count, &read_count, NULL); if (!is_ok) { error_setg_win32(errp, GetLastError(), "failed to read file"); --=20 2.17.2