Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp714864imm; Thu, 13 Sep 2018 06:43:37 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaMRMc/471vx/zglcBYOW5c5Bu0BXB3aa8N6sxlrRI9ZJK0wQh7yZYp6oi99tiKG94fKsjg X-Received: by 2002:a63:a012:: with SMTP id r18-v6mr1621104pge.166.1536846217502; Thu, 13 Sep 2018 06:43:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536846217; cv=none; d=google.com; s=arc-20160816; b=t8i5kWqtr34ptrHgNLOEgaxlxFe5dhdRRkbem6TLs3AqBy9WWMuqvO0OS9IH9mersH qnMZBVs/J7/e/GP/xs1WjaMzepE4qicMjQxQKgWMc4uiuBdo7DP1rtfHcYFzjauGjvcW r8LO6mVDqvTZ/M0cK384eeLtq2n3tRQV5cukiGW1wfaOoXEK5/JqU+dRT8dU5G/emc0t 51sRwDmNU+NRVA+FCE/TThLj+2S6PFTk5D2+Oxd+ck9KFNpbrQRgHVgJ8oYWqA2kG6lk 1hC95MS20cblYHvde2l7wDMlWf0q5qGXNgpcjnncZ2mbLXGw9XYBq25WS7VqDGRX/lT/ DxNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=ugqV1uie46oZ+cA+8mVQoCFwjkKRkuPdB4jsTWvwLxc=; b=Qbqu7eIlMOnTn90RuoRMCpS52SU+Jjq2cy8f7tNklkl98ippmy8hwrzWdnQG2OkF1q UytNOsNFuoLNY6JGALJwa02yZqYSOByR6AWCREAUD3qfeJH8KLsdZIDbaKs9/0/Yr6An L+J+0vr67G94Og/Dt6lFRNTG3aZ1RZOkENAMXcKPrF1U8Zkky0B88uo/eUZww27Op6oo ckVq2MU5cRyfr/SL1lZLEeU2lgWahoc6ddMlLmUHPNDjgyecLVART8BtCgBXglQWwKsE 1Dvr2U7edE1zJfeLitMQGxxmTw3Ly+O6wmZZcaB2GQ39wIACE8a722zjQ6u/lNbovJS1 Lj0g== 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 p61-v6si4152301plb.55.2018.09.13.06.43.22; Thu, 13 Sep 2018 06:43:37 -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 S1729814AbeIMSwl (ORCPT + 99 others); Thu, 13 Sep 2018 14:52:41 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60292 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728860AbeIMSwk (ORCPT ); Thu, 13 Sep 2018 14:52:40 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id F2A10CF3; Thu, 13 Sep 2018 13:43:07 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Marc Zyngier , Christoffer Dall , Peter Maydel , Jean-Philippe Brucker , Suzuki K Poulose , Sasha Levin Subject: [PATCH 4.14 031/115] virtio: pci-legacy: Validate queue pfn Date: Thu, 13 Sep 2018 15:30:51 +0200 Message-Id: <20180913131825.577708462@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131823.327472833@linuxfoundation.org> References: <20180913131823.327472833@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Suzuki K Poulose [ Upstream commit 69599206ea9a3f8f2e94d46580579cbf9d08ad6c ] 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 Signed-off-by: Michael S. Tsirkin Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/virtio/virtio_pci_legacy.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) --- a/drivers/virtio/virtio_pci_legacy.c +++ b/drivers/virtio/virtio_pci_legacy.c @@ -122,6 +122,7 @@ static struct virtqueue *setup_vq(struct 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,17 @@ static struct virtqueue *setup_vq(struct 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, + "platform bug: legacy virtio-mmio must not be used with RAM above 0x%llxGB\n", + 0x1ULL << (32 + PAGE_SHIFT - 30)); + err = -E2BIG; + 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 +169,7 @@ static struct virtqueue *setup_vq(struct out_deactivate: iowrite32(0, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN); +out_del_vq: vring_del_virtqueue(vq); return ERR_PTR(err); }