From nobody Mon Feb 9 16:02:50 2026 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585663672; cv=none; d=zohomail.com; s=zohoarc; b=akVhmib2uwZ1OgnwJ74kWBwXAUpdS3VY8UFBEoTG1yVYFf1n334LFVrVtImaDFEh0ooIqAGrsMBecxDehIm7rfZqh8yAOzIAJU4kYMlOt4V4q80Qppq1rB7IdHzDwZ75WTNwc7u4YUgcJIK9ENdyVKhNxudLjnw8oS5DyPSz/0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585663672; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HFKw99eybEBSOFz3dUXtZpLQZvMzVUyCJ6arSOjZUVc=; b=SKONjL3QqYk7RGzKKBnoE/BUC8W62EoS0lBBqMkk8UMf7gkV2NIJ6u4I0tlcDaznLO2VJpOYrxNO9JL23924yz2gfwyDy6IggqaCuxmXXUPVHrAIPXOk8L5KBXbgqWZ94qrbNGOiWW8/B28P7GsGfs9GKUJQeSvnYliMFJE77mk= 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585663672158103.53908744366197; Tue, 31 Mar 2020 07:07:52 -0700 (PDT) Received: from localhost ([::1]:38616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJHYU-0003OT-3u for importer@patchew.org; Tue, 31 Mar 2020 10:07:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47886) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJHXX-0002Es-P6 for qemu-devel@nongnu.org; Tue, 31 Mar 2020 10:06:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJHXW-0007dQ-QC for qemu-devel@nongnu.org; Tue, 31 Mar 2020 10:06:51 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:53210 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 1jJHXW-0007d4-MX for qemu-devel@nongnu.org; Tue, 31 Mar 2020 10:06:50 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-339-KaR1cyJkO2STxyv_39RG4g-1; Tue, 31 Mar 2020 10:06:48 -0400 Received: by mail-wm1-f69.google.com with SMTP id e16so505526wmh.5 for ; Tue, 31 Mar 2020 07:06:48 -0700 (PDT) Received: from localhost.localdomain (116.red-83-42-57.dynamicip.rima-tde.net. [83.42.57.116]) by smtp.gmail.com with ESMTPSA id u128sm4025190wmu.31.2020.03.31.07.06.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 07:06:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585663610; 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=HFKw99eybEBSOFz3dUXtZpLQZvMzVUyCJ6arSOjZUVc=; b=LjW/tyATsSQvYtB5ay7dPkhq9lb2gKhzeK4qkpfSiQ6wlpEbXofwt9ooJSfQFsOd+S+q7T eZxZLJsoGjF8FuQAFZHBzwGxBkJlyLo84Th1mMK1JzlkxzLzdykAY6JfbtQhD6CcU8OSg2 fh/++nIgzBoPtt3F2RJDK9Zp801KZYk= X-MC-Unique: KaR1cyJkO2STxyv_39RG4g-1 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:mime-version:content-transfer-encoding; bh=YhmapbcU5a1HoNpuFF+HAiAFJ1ozuO4gZZnYbW0h/jM=; b=mKmUql0XJ935suHOX5xc3lUX8Yml/EhuDC4QOzbcPS5atnneKHqTI4mOYqkUVX7FbW rc3LqPxf+Vlw/VbMB7ZZL1IKMHtiLWb0rRw5UZwMNRnVm4t0bX0l/CyNcLXf5/exrpQ3 eUsSXlPk6TXUiC5PI2WwiXqxQvp6BJi++AX4cZ09S2YNnxMGPgeyIJ3qC7reR0y/SbC6 aSjrlDf5dPqzARS3iMfSB4kVUCq4b6IBDS8Zb45ZIcC5d06SewnFqgLtkHsWL7pCkkMY 9de2EtEOKqyZkyZqSbfoAnsTkNCxE72UlPIwmWRp58zGwjkPXMi4vnmw72NeZnNRiXUR bMjg== X-Gm-Message-State: ANhLgQ0izMVzAyewU+jZJjW6hxVrSroQEmskoiCTMUaXwfcgg9oXkei3 SEHGR5anwulOva7GTe1mDcnuo09NU/bPwlhePbTw7hUUHtcASZhLTFOfhEuEg53HXGMm3UeoHQW Y0+aw5KgxdeGiMF0= X-Received: by 2002:a7b:ce95:: with SMTP id q21mr3818977wmj.65.1585663607329; Tue, 31 Mar 2020 07:06:47 -0700 (PDT) X-Google-Smtp-Source: ADFU+vviFCLsHP+ZYvcT+aQatfMvktmNgf8A/W71hBKHbnQ0zXh2PQ15vZ5fQmWC4vHPjp5yn5EleA== X-Received: by 2002:a7b:ce95:: with SMTP id q21mr3818965wmj.65.1585663607134; Tue, 31 Mar 2020 07:06:47 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH-for-5.0 v2 1/4] Revert "prevent crash when executing guest-file-read with large count" Date: Tue, 31 Mar 2020 16:06:35 +0200 Message-Id: <20200331140638.16464-2-philmd@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200331140638.16464-1-philmd@redhat.com> References: <20200331140638.16464-1-philmd@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: 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?Daniel=20P=20=2E=20Berrang=C3=A9?= , Markus Armbruster , Michael Roth , Fakhri Zulkifli , "Dr . David Alan Gilbert" , Sameeh Jubran , Basil Salman , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Dietmar Maurer Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" By using g_try_malloc() instead of g_malloc() the qemu-guest-agent Denial-of-Service attack referred in commit 807e2b6fce is reduced, but still triggerable: - bisect file size S until g_try_malloc(S) fails, - use S - 1: g_try_malloc(S - 1) succeeds, but g_new0() few lines later will fail. 346 buf =3D g_try_malloc0(count + 1); 347 if (!buf) { 348 error_setg(errp, 349 "failed to allocate sufficient memory " 350 "to complete the requested service"); 351 return NULL; 352 } 353 is_ok =3D ReadFile(fh, buf, count, &read_count, NULL); 354 if (!is_ok) { 355 error_setg_win32(errp, GetLastError(), "failed to read file"); 356 slog("guest-file-read failed, handle %" PRId64, handle); 357 } else { 358 buf[read_count] =3D 0; 359 read_data =3D g_new0(GuestFileRead, 1); ^^^^^^ Instead we are going to put a low hard limit on 'count' in the next commits. This reverts commit 807e2b6fce022707418bc8f61c069d91c613b3d2. Suggested-by: Daniel P. Berrang=C3=A9 Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- qga/commands-win32.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index b49920e201..46cea7d1d9 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -343,13 +343,7 @@ GuestFileRead *qmp_guest_file_read(int64_t handle, boo= l has_count, } =20 fh =3D gfh->fh; - buf =3D g_try_malloc0(count + 1); - if (!buf) { - error_setg(errp, - "failed to allocate sufficient memory " - "to complete the requested service"); - return NULL; - } + buf =3D g_malloc0(count + 1); is_ok =3D ReadFile(fh, buf, count, &read_count, NULL); if (!is_ok) { error_setg_win32(errp, GetLastError(), "failed to read file"); --=20 2.21.1