From nobody Tue Apr 23 20:05:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1585070804; cv=none; d=zohomail.com; s=zohoarc; b=O54Rvotwrf6THBK9990kNlmVn+PTsybtVRRKyhRc44RamwcwF2+9fIcVbgDwFA01JsxyG87dJFvuYwl4xbEUj+Gu/VtaNW2KmlA3jLsaPyma+7yT+i1YMe/lHGta/mp2z7jAPivaw91BE6XDckFBvLp3Cpja9l/WYsKxjE7xt88= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585070804; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=2fuYUPCJuYkPjACVZLJEBgaE+J81FBCDK3U9qpFDHAY=; b=hKm1wLNnJ8wTuaGAXL4uF8anbvYMR7TorWxrG3hTsQQ8ClzqZULTrTWJHF/aTKIf9uqU88duGXS0fDmDLkpLO/rR3pmA2eujgfSS872s4LddPZ+ACQKdyA8rvSmVwqFHcUtLD+IwB6x2IaDg+GT3C0RWhR5iA1faYs4+Xj5/BLo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585070804241835.936369854819; Tue, 24 Mar 2020 10:26:44 -0700 (PDT) Received: from localhost ([::1]:52576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGnK7-0004av-1N for importer@patchew.org; Tue, 24 Mar 2020 13:26:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51088) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGmiT-0003SW-A2 for qemu-devel@nongnu.org; Tue, 24 Mar 2020 12:47:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGmiS-0007vQ-5N for qemu-devel@nongnu.org; Tue, 24 Mar 2020 12:47:49 -0400 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:34801) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jGmiS-0007v8-0W; Tue, 24 Mar 2020 12:47:48 -0400 Received: by mail-ot1-x341.google.com with SMTP id j16so17699797otl.1; Tue, 24 Mar 2020 09:47:47 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id g130sm6431258oif.13.2020.03.24.09.47.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Mar 2020 09:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=2fuYUPCJuYkPjACVZLJEBgaE+J81FBCDK3U9qpFDHAY=; b=MvXvYcM4GKriw2qm1GQUUO1kC3qjC6t57C2XVjfHXowg97aEqFjzcnSt2sVIVVAXNv G1uZ8/n3n2CvyozwTZ432jJVXD6qof3Itf6fwIq7Lkryd/0+177X9UqJvvpkTLxKoy0e 4GW7Zj63muMzC3HbhbJui3rQwUiJUJ0D7nmh2f0XXNyid519JeN3vJ8/tFQ7PdtjZiC+ JjkqDtZew9mtGZP085ytq+GDEf5X1f54AdXvFNiwIz8nvQU9x/eftIkh/CiY6BdbkT60 MlanWUnVcm/zkBCKJ8mdU3DfqTxpKg9XN9YyeUHZzgf51TNuB/ewFaCxryA9cVZ0YjJr IOaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=2fuYUPCJuYkPjACVZLJEBgaE+J81FBCDK3U9qpFDHAY=; b=iKqA8qsR0E+kRjGPZhEze1XhVPRg8LasGFRP1p86Zx1MjFdpPzLGxJvo1L1z59hE95 WvlPE9u7HVVK53yxSRLjo61OMBdyJbubUoFg/WOa1j2u6ir8hbG6KFlTKIzApSTPRksN Zn3wEHGBnKs8OSdxM7ie9HReY8ZxYmwocvdUAEazo15T489d29Z3W3kcOqC7rl1B7BQa fEkTEvS66OPUssqYaeOSu3PEXx/tS9bSiDfQyUFZumjmiWwlyk+m+6/PZwIEOxj4fvCy P7xERji1AmnGpjEe5enMZY6UMFL73/cCRrMcarUI5LfADd3NA7UGc72i1CtoK3Dherel bl7w== X-Gm-Message-State: ANhLgQ1L2IafWLZ4zXwffDgqNu9KAfQ2+swON3EUzaDeZ6xE6nVe8/9z hXVWTaZPRQgREcUkC7qkhm0ergmY2wI= X-Google-Smtp-Source: ADFU+vsUacAU8LOG47iyWyUDyEVBhA/ZdxSvlFyCl3sG7O6IK9tXjaGFAiL+ixYqDq4S5ORAwaLPTA== X-Received: by 2002:a9d:412:: with SMTP id 18mr22000135otc.134.1585068466581; Tue, 24 Mar 2020 09:47:46 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL for-5.0 3/5] qga-win: prevent crash when executing guest-file-read with large count Date: Tue, 24 Mar 2020 11:46:51 -0500 Message-Id: <20200324164653.19449-4-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200324164653.19449-1-mdroth@linux.vnet.ibm.com> References: <20200324164653.19449-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::341 X-Mailman-Approved-At: Tue, 24 Mar 2020 13:24:17 -0400 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: peter.maydell@linaro.org, qemu-stable@nongnu.org, Basil Salman 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" From: Basil Salman guest-file-read command is currently implemented 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. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1594054 Signed-off-by: Basil Salman Reported-by: Fakhri Zulkifli Cc: qemu-stable@nongnu.org Signed-off-by: Michael Roth --- 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 9c744d6405..b49920e201 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -343,7 +343,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 NULL; + } 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.1