From nobody Mon Nov 17 08:01:08 2025 Delivered-To: importer@patchew.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=nutanix.com ARC-Seal: i=1; a=rsa-sha256; t=1603725257; cv=none; d=zohomail.com; s=zohoarc; b=N7u9UDabel0Q56VAjINZkRb1z7oKsOGZ3XfXnHOSxN2ym921md1l6vZsNZp05PR8kSBmglsjTJc4fVGfRN1+OAVnD5vW2VT0+GkKzeadquUnaNBgoXDe3iN17BbzKD6dI6iEgDO5QHqYBHn24fjUS2nywjzHz7dHM2SJpwFomN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603725257; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=jaanafTkjnT9BbTRRApXu/QeiKkgwYKMKutp+gyNGPI=; b=j9CO3PQUuwSHQarmSyYGqolmwtTLVmg5KL5dLYhnhBqL+lwcP0zl9jXkvVGB/pZeeToydR7hoFaM65t5AqjvXHSMHIk2reF0rBJVQqQXZkU0dyoOheh/CrBgMe92GPKkiMhcJu2aHzRv2+rc4lA4r7gBMXzaNOgWzl9aKLTaRMQ= 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 1603725257317685.872398758269; Mon, 26 Oct 2020 08:14:17 -0700 (PDT) Received: from localhost ([::1]:54440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kX4CO-0002nD-Ln for importer@patchew.org; Mon, 26 Oct 2020 11:14:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35398) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kX4Bl-0002Js-BB for qemu-devel@nongnu.org; Mon, 26 Oct 2020 11:13:37 -0400 Received: from o1.dev.nutanix.com ([198.21.4.205]:52529) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kX4Bj-0005vP-OZ for qemu-devel@nongnu.org; Mon, 26 Oct 2020 11:13:37 -0400 Received: by filterdrecv-p3las1-bf7bc68d5-fmkt4 with SMTP id filterdrecv-p3las1-bf7bc68d5-fmkt4-19-5F96E79C-8E 2020-10-26 15:13:32.665192997 +0000 UTC m=+422065.423749127 Received: from felipe-franciosi-cent7-umvm1.dev.nutanix.com (unknown) by ismtpd0004p1sjc2.sendgrid.net (SG) with ESMTP id W-jp9stEQvCIceFl7tuICw Mon, 26 Oct 2020 15:13:32.538 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sendgrid.net; h=from:subject:to:cc:content-type:content-transfer-encoding; s=smtpapi; bh=jaanafTkjnT9BbTRRApXu/QeiKkgwYKMKutp+gyNGPI=; b=C+cEi/VW8mQ9uaQyUry5bwTa1lDLQplGzSv6z2zPH5PH+/4tHqGG+f7S0u/6troeRe0l zsSrWTZDvH3GJl3/yug+2/9DxymK5V4/gRBW67X22d5rhJyaQ5j4bCSJ3Qg3ma5WY01Yjb Lly6udbOezuCxfw+BzrrhVpdzytxAWXvY= From: Felipe Franciosi Subject: [PATCH] virtio: skip guest index check on device load Date: Mon, 26 Oct 2020 15:13:32 +0000 (UTC) Message-Id: <20201026151328.77611-1-felipe@nutanix.com> X-Mailer: git-send-email 2.18.4 X-SG-EID: =?us-ascii?Q?W9goRmNI2M6BaZDnSanVWLdj2DuGbkuGfTWZsqFIAk59ONbkkaLXMDCghpkcaI?= =?us-ascii?Q?PehS=2FLuf7=2F3t083SnZbMEjVxFPrrK521N5u7r+e?= =?us-ascii?Q?7gR2ZIIk++M23YxqkvjCwQFt2W5uyP2wMCHFym2?= =?us-ascii?Q?AQVeWr=2Fjk5XodB2P8URd+X08wBcCROglJjjCPEz?= =?us-ascii?Q?a5wczAk5c0d061q1si7TvWpISrhwMlTO0YqeItO?= =?us-ascii?Q?l0+PaXhxqFcdZejBgJ7cj0b2KSzcSfLWyZmowwR?= =?us-ascii?Q?Q4eKU90A+X61rfIIjbR+w=3D=3D?= To: qemu-devel@nongnu.org X-Entity-ID: IZcDqzhM+W+fx+coAjH1TQ== Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=198.21.4.205; envelope-from=bounces+19088175-f42a-qemu-devel=nongnu.org@sendgrid.net; helo=o1.dev.nutanix.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/26 11:13:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=no autolearn_force=no X-Spam_action: no action 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: "Michael S . Tsirkin" , Jason Wang , Markus Armbruster , Stefan Hajnoczi , Felipe Franciosi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" QEMU must be careful when loading device state off migration streams to prevent a malicious source from exploiting the emulator. Overdoing these checks has the side effect of allowing a guest to "pin itself" in cloud environments by messing with state which is entirely in its control. Similarly to what f3081539 achieved in usb_device_post_load(), this commit removes such a check from virtio_load(). Worth noting, the result of a load without this check is the same as if a guest enables a VQ with invalid indexes to begin with. That is, the virtual device is set in a broken state (by the datapath handler) and must be reset. Signed-off-by: Felipe Franciosi --- hw/virtio/virtio.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 6f8f865aff..0561bdb857 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3136,8 +3136,6 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int = version_id) RCU_READ_LOCK_GUARD(); for (i =3D 0; i < num; i++) { if (vdev->vq[i].vring.desc) { - uint16_t nheads; - /* * VIRTIO-1 devices migrate desc, used, and avail ring address= es so * only the region cache needs to be set up. Legacy devices n= eed @@ -3157,16 +3155,6 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int= version_id) continue; } =20 - nheads =3D vring_avail_idx(&vdev->vq[i]) - vdev->vq[i].last_av= ail_idx; - /* Check it isn't doing strange things with descriptor numbers= . */ - if (nheads > vdev->vq[i].vring.num) { - error_report("VQ %d size 0x%x Guest index 0x%x " - "inconsistent with Host index 0x%x: delta 0x%= x", - i, vdev->vq[i].vring.num, - vring_avail_idx(&vdev->vq[i]), - vdev->vq[i].last_avail_idx, nheads); - return -1; - } vdev->vq[i].used_idx =3D vring_used_idx(&vdev->vq[i]); vdev->vq[i].shadow_avail_idx =3D vring_avail_idx(&vdev->vq[i]); =20 --=20 2.18.4