Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1187516imm; Fri, 29 Jun 2018 13:02:23 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJeAGZRLsEqbdAeQQhvlHOuNOqk3r+uya6Vty4sSDE784Go66wDu6HVBao5cbW+gTWnIpqi X-Received: by 2002:a17:902:28a6:: with SMTP id f35-v6mr16255566plb.110.1530302543567; Fri, 29 Jun 2018 13:02:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530302543; cv=none; d=google.com; s=arc-20160816; b=rZ5UT3biFalohENUs1Zkc20D7IByxpDioAagJ1eccNWD0jD0Oqa9QlHZQEhSczNdgb Dj49hBA1BqSjbeUZ7SNyK1abSDcL4NDp6FbRh7y4nnTH9EcVxPmPGzaGTrh8CaqjAWGk 6hM9Pri38UhdfMPxmbWKr1ll9gci65JlZj+WjN+ta8JYZh6gVppNl3SzGGXMayrLqsi/ AxvYOzN3VDGanK8Wm0rwLfjADn1STQJxfB28drxJx2L1szXrV/ink3ApdHH/gHb4Zvfr bo6yXvveVaXXHbjf67Vx3mN0IBF/3DPj3Uk28cFHb6OvDpIAmY1WkuGEL+Uo1Ma9pY2M qp0g== 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=n4qt/UqPtSm9/ZOdJ4V5mg76ikSAzEEVwslphSEtOtM=; b=EDdHIFVYFT06d8ehGlHUs8QMC8ihngwRYFpSUw9FqzGV8v2KuB206JiXBE2w8aO1uj m1ZtC2LBllfjk3tcVXUdTroLkMO3aoicEXGSZOGF+SFgO/chXDYl9Xi2NNAJN6PECE4A MPrFGBJwdtLvbSms0mqQrOZqzmWk4nFNvnnspzTauXsApx9vK38pSpjj5fiJWg10DHdU +1RxdGRMltCLE4cQ/ZgvZRWku8FyV/mxiZrWRB2WwJ6XGmXqrmy1AgO6KPeGnOXxiC+U v3kTrcSwS40AZXfyfOfWci9oyWrkvG1GyO1DedNBB09e155NUaDp2hPJhfXQVLhphgCY ZJjg== 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 d20-v6si8737285pgb.682.2018.06.29.13.02.09; Fri, 29 Jun 2018 13:02:23 -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 S933674AbeF2RmH (ORCPT + 99 others); Fri, 29 Jun 2018 13:42:07 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37720 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752934AbeF2RmG (ORCPT ); Fri, 29 Jun 2018 13:42:06 -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 A4A44818594D; Fri, 29 Jun 2018 17:42:05 +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 A06B91D089; Fri, 29 Jun 2018 17:42:02 +0000 (UTC) Date: Fri, 29 Jun 2018 20:42:02 +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 01/20] virtio: mmio-v1: Validate queue PFN Message-ID: <20180629200816-mutt-send-email-mst@kernel.org> References: <1530270944-11351-1-git-send-email-suzuki.poulose@arm.com> <1530270944-11351-2-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-2-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:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 29 Jun 2018 17:42:05 +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:21PM +0100, Suzuki K Poulose wrote: > virtio-mmio with virtio-v1 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_mmio.c | 18 ++++++++++++++++-- > 1 file changed, 16 insertions(+), 2 deletions(-) > > diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c > index 67763d3..82cedc8 100644 > --- a/drivers/virtio/virtio_mmio.c > +++ b/drivers/virtio/virtio_mmio.c > @@ -397,9 +397,21 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned index, > /* Activate the queue */ > writel(virtqueue_get_vring_size(vq), vm_dev->base + VIRTIO_MMIO_QUEUE_NUM); > if (vm_dev->version == 1) { > + u64 q_pfn = virtqueue_get_desc_addr(vq) >> PAGE_SHIFT; > + > + /* > + * virtio-mmio v1 uses a 32bit QUEUE PFN. If we have something > + * that doesn't fit in 32bit, fail the setup rather than > + * pretending to be successful. > + */ > + if (q_pfn >> 32) { > + dev_err(&vdev->dev, "virtio-mmio: queue address too large\n"); How about: "hypervisor bug: legacy virtio-mmio must not be used with more than 0x%llx Gigabytes of memory", 0x1ULL << (32 - 30) << PAGE_SHIFT > + err = -E2BIG; > + goto error_bad_pfn; > + } > + > writel(PAGE_SIZE, vm_dev->base + VIRTIO_MMIO_QUEUE_ALIGN); > - writel(virtqueue_get_desc_addr(vq) >> PAGE_SHIFT, > - vm_dev->base + VIRTIO_MMIO_QUEUE_PFN); > + writel(q_pfn, vm_dev->base + VIRTIO_MMIO_QUEUE_PFN); > } else { > u64 addr; > > @@ -430,6 +442,8 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned index, > > return vq; > > +error_bad_pfn: > + vring_del_virtqueue(vq); > error_new_virtqueue: > if (vm_dev->version == 1) { > writel(0, vm_dev->base + VIRTIO_MMIO_QUEUE_PFN); > -- > 2.7.4