Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp894107imm; Fri, 29 Jun 2018 08:04:51 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLF4HUFfvKQYrh9/UtUYovZyVfELcOl6d+0XWZXt/Av4o7NnjKj7FBc2HNW/J/4DFNL0b1D X-Received: by 2002:a65:6147:: with SMTP id o7-v6mr12994138pgv.163.1530284691016; Fri, 29 Jun 2018 08:04:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530284690; cv=none; d=google.com; s=arc-20160816; b=iHjPPdFVpQwok5KeICtNHolqeMxe4W3JuFwsVVcqfOz5t6GlbcIy7SvWxyVpLUwMDK bs9aAo96VA0llRJ5wjVit2B0ToyqGYtPDGolfXHvU9BnSoGcN+AK0yQF03NWVJMRCFCe mIwSd+kLzQW7qxy4EZXTKCeOS0k5qAqSEADSiSIqcfkcmEtPJwWxu1bPzLix8bxJbKwy UN0kxEJBU2j4wQCVZGoechU/7YAtdeDJX/0K7DRzsEzmi6Xhys4+8Yusq1dIRUN+MYMn 5HQSrn3/epEdBY5SXneSJPNUz95xbZeKPQQPjN5GYIrn5ML4eeb3mKt6Bv4dfjvnQNYf xr+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=aOLRsXU0c0TCHjrIc9j3ae+sNB3T4hrqj5DBtjtmoWM=; b=t1652AdvqyqkODcIZRYgjxX9BO9NTJAyBq9zUqlwKXGYWeFFtOctCfWCAcDN6+vMb5 f/wNHpQ3iuDkBN4IaGwTEEvKC0C+5LjaaGYUWFFim1KA8xDYkTO48sFf4PUcd8cM958x IFgGQ4aNnRPZrytQkDfxKYMiDLkb67PxlzZucxjdCpxbw60NtlZHkg2GIySRhO9MIib1 pl1YxiXyNjlDgWQSWqrnhVOxrC4BNviMHpouI9UoQNwP7/dcwwWDfA2YSIU9orofUKUa NrOwwQuQFyZWlVC0qE66IdcQJQHMaLt8w501CEWiamUMkMiL+gBSfcdo80EG2xIe4t4d Ca+w== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v14-v6si8911269pfe.149.2018.06.29.08.04.30; Fri, 29 Jun 2018 08:04:50 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755185AbeF2LQX (ORCPT + 99 others); Fri, 29 Jun 2018 07:16:23 -0400 Received: from foss.arm.com ([217.140.101.70]:60022 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755152AbeF2LQQ (ORCPT ); Fri, 29 Jun 2018 07:16:16 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 00FB01529; Fri, 29 Jun 2018 04:16:16 -0700 (PDT) Received: from en101.cambridge.arm.com (en101.cambridge.arm.com [10.1.206.73]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 104AB3F266; Fri, 29 Jun 2018 04:16:12 -0700 (PDT) From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Cc: 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, Suzuki K Poulose , "Michael S. Tsirkin" , Jason Wang , Peter Maydel , Jean-Philippe Brucker Subject: [PATCH v3 01/20] virtio: mmio-v1: Validate queue PFN Date: Fri, 29 Jun 2018 12:15:21 +0100 Message-Id: <1530270944-11351-2-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530270944-11351-1-git-send-email-suzuki.poulose@arm.com> References: <1530270944-11351-1-git-send-email-suzuki.poulose@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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"); + 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