Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1065209imm; Fri, 29 Jun 2018 10:45:49 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLYZepGZ2D80OIn0PDI71ZCBGwpz99G7OovdBIb4GiEEcaX+Qrc7hZM/IeI8p76PuHBC2uq X-Received: by 2002:a65:6007:: with SMTP id m7-v6mr13061969pgu.92.1530294349690; Fri, 29 Jun 2018 10:45:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530294349; cv=none; d=google.com; s=arc-20160816; b=Nmfwtcg/Ap40P9lBkanRLGILnaVSp/xZGN+heHWX3qoudOHPyOhYJjloJrOZfog4u3 qFy0ZxWu9HzYtziXu8LihPpCDOIesKSXzQrXwRBJKrkA017VnQOqj3tHWPahCYrV4p+O VbtI9Igrkxmoe8zLupmdOZF7w/2qXuWBxpALlsePNpM1fdUrpmU997Ny/CEJfmUtgSOP 4ORLIucx8eS+6LSb4A4AHihrc2B9t6CYxIy0FcaXrU4G2ZEDSMmOgv4qWcMPVPT2buIj OUyyJ+0EGpAYDXRTGIZdmhAdCsfXmPxLgfhuqAdhXw9CVD9aQav4ZHkKkPe7KGh3sh9y 4K0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=tr9s3HpKrK0PW9CqDqTnWldddvsF3m7OqWdBEB3J2hM=; b=WSvE5XcWl9hwidPlLjxTuQHEJMLQUI252FUWD/AnAIcr6NwYRz7bRadmsVwP62F+ZD saJLJGeqdFE0dSapNE9jIQ3KPZoseDOVqVZarHYqOjZXCvjy1EBvDUiivk0y9s1IvvOR 7hYUkNUA3NzS0v52R4cKF28h9cFU5aUPjZXuhg+V/V3c4ru7J21GKyKL+Y5xZqPK2mk/ VA+Fl/K+q8WifWysfGj28zyED+dSjNp9O7jAQ4KK0e33HrSg/xlpC/qJVxua6N/FCSo3 gaNUUCMH2T6RLLC0D6B0jRXemZUWXFHblEKfxG/Q1I7nbtBl4PpytGN9ehir6i4r5SPB ONIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x5-v6si52659pgc.210.2018.06.29.10.45.34; Fri, 29 Jun 2018 10:45:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754632AbeF2Rmq (ORCPT + 99 others); Fri, 29 Jun 2018 13:42:46 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37754 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753523AbeF2Rmo (ORCPT ); Fri, 29 Jun 2018 13:42:44 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F32F7818594D; Fri, 29 Jun 2018 17:42:43 +0000 (UTC) Received: from redhat.com (ovpn-120-120.rdu2.redhat.com [10.10.120.120]) by smtp.corp.redhat.com (Postfix) with SMTP id 126FE1D084; Fri, 29 Jun 2018 17:42:41 +0000 (UTC) Date: Fri, 29 Jun 2018 20:42:40 +0300 From: "Michael S. Tsirkin" To: Suzuki K Poulose Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, james.morse@arm.com, marc.zyngier@arm.com, cdall@kernel.org, eric.auger@redhat.com, julien.grall@arm.com, will.deacon@arm.com, catalin.marinas@arm.com, punit.agrawal@arm.com, qemu-devel@nongnu.org, Jason Wang , Peter Maydel , Jean-Philippe Brucker Subject: Re: [PATCH v3 02/20] virtio: pci-legacy: Validate queue pfn Message-ID: <20180629204213-mutt-send-email-mst@kernel.org> References: <1530270944-11351-1-git-send-email-suzuki.poulose@arm.com> <1530270944-11351-3-git-send-email-suzuki.poulose@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1530270944-11351-3-git-send-email-suzuki.poulose@arm.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 29 Jun 2018 17:42:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 29 Jun 2018 17:42:44 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mst@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 29, 2018 at 12:15:22PM +0100, Suzuki K Poulose wrote: > Legacy PCI over virtio uses a 32bit PFN for the queue. If the > queue pfn is too large to fit in 32bits, which we could hit on > arm64 systems with 52bit physical addresses (even with 64K page > size), we simply miss out a proper link to the other side of > the queue. > > Add a check to validate the PFN, rather than silently breaking > the devices. > > Cc: "Michael S. Tsirkin" > Cc: Jason Wang > Cc: Marc Zyngier > Cc: Christoffer Dall > Cc: Peter Maydel > Cc: Jean-Philippe Brucker > Signed-off-by: Suzuki K Poulose > --- > Changes since v2: > - Change errno to -E2BIG > --- > drivers/virtio/virtio_pci_legacy.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c > index 2780886..c0d6987a 100644 > --- a/drivers/virtio/virtio_pci_legacy.c > +++ b/drivers/virtio/virtio_pci_legacy.c > @@ -122,6 +122,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, > struct virtqueue *vq; > u16 num; > int err; > + u64 q_pfn; > > /* Select the queue we're interested in */ > iowrite16(index, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_SEL); > @@ -141,9 +142,15 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, > if (!vq) > return ERR_PTR(-ENOMEM); > > + q_pfn = virtqueue_get_desc_addr(vq) >> VIRTIO_PCI_QUEUE_ADDR_SHIFT; > + if (q_pfn >> 32) { > + dev_err(&vp_dev->pci_dev->dev, "virtio-pci queue PFN too large\n"); > + err = -E2BIG; Same comment here. Let's make it clear it's host not guest problem. > + goto out_del_vq; > + } > + > /* activate the queue */ > - iowrite32(virtqueue_get_desc_addr(vq) >> VIRTIO_PCI_QUEUE_ADDR_SHIFT, > - vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN); > + iowrite32(q_pfn, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN); > > vq->priv = (void __force *)vp_dev->ioaddr + VIRTIO_PCI_QUEUE_NOTIFY; > > @@ -160,6 +167,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, > > out_deactivate: > iowrite32(0, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN); > +out_del_vq: > vring_del_virtqueue(vq); > return ERR_PTR(err); > } > -- > 2.7.4