Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1249083pxb; Fri, 22 Jan 2021 10:31:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJwjXOuDdWzVmAuicXQ4Qfuf6z1QCMPtpkuXE/5r91xRhXKfQPRBl4UhPEBM91RRU/uQkJGZ X-Received: by 2002:aa7:d5d5:: with SMTP id d21mr664331eds.252.1611340293906; Fri, 22 Jan 2021 10:31:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611340293; cv=none; d=google.com; s=arc-20160816; b=OMO23gTPdfaxXt+zSrIkk+o2K49fDb5zdqyyR/kXHCKIkI5N+ffehReWbs6PBHvMWD Ns7CtjjRLC9lKeTSyONmZvtq7qUGplm7EVpS+EuTCer+dnWmsZGeg6vTb4P8RNlDu7+F pLZsJ83VTYj6yOz+iHiMgfe4JhCci/MQHHLfNUDdoTh+LRO8jgbiCcAY5AVORA35HISQ 6L1j105qd/TcjgBCZK9uzho3KQXfK3XpohmUwBEoKHFK7yxW1g9/9nSqkImSxjkZXCbS USmC4/eoZioLpQEi98+SeM9BbXugPvdutvg8xM0CL77o/7HlnP1yHdZuh3ZP0Dot9tBH acTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=V0kp5KFHTpFFgSuvTeXFgF/5KcXBY1m3fsYZ7cMLUXA=; b=pBH4VMziIfy4HjybngKQEjXgVhe1FAoOBsuuvu9TtuKyrIUkl7Pjf2ST4/HcBfK4Vk MBUpOTKsAD1/MVY1wFB4uwJF1SI3Heqaf2nGr2t/m3rEjDRvI2W85Na9Lkr6oi6OPbr3 5vjPpZLqz7Jbw42w5gll7SkPw2zT482YHn5t1q6fOmSbJ9Plb9k/OZbiLpmp8s0079pA bC9KS/5UowX4MN3C7FnIcKCovUDeGtjiVM1q1g3pQna8c4nSCVbsg9259cpNsZzVTNFw Ilqh6OyfswAcptJGLP6yG21ik/5jq1MoKqN/0X6ZQrYacuHOPnIY5mktNNyVAzWOOnlV sqxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TL+Aru9H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i26si3969912edx.182.2021.01.22.10.31.09; Fri, 22 Jan 2021 10:31:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TL+Aru9H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729322AbhAVS22 (ORCPT + 99 others); Fri, 22 Jan 2021 13:28:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:39060 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728561AbhAVOWy (ORCPT ); Fri, 22 Jan 2021 09:22:54 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id AB64823B75; Fri, 22 Jan 2021 14:16:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1611325011; bh=cVXMJvY5hJuBfENHnD5krYolc/OGDjdSaxeJg4eN1JA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TL+Aru9HjVaPUXPi6dB4Lat4emlwdVsXnkTThIiM4X7lZcC3wepULtZmuLtFUYTw7 FxsPIgLhXkIHwBu0X1USHe36cq5/D/5cBrttpcxEAaBexTTPz98bgH5ADfRsNAksxc P80gn9kGkeZj5oQ8aRKL3U4iO2e7fu4HMX1guCr8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Juergen Gross , Andrew Cooper Subject: [PATCH 5.4 03/33] xen/privcmd: allow fetching resource sizes Date: Fri, 22 Jan 2021 15:12:19 +0100 Message-Id: <20210122135733.712747023@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210122135733.565501039@linuxfoundation.org> References: <20210122135733.565501039@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Roger Pau Monne commit ef3a575baf53571dc405ee4028e26f50856898e7 upstream. Allow issuing an IOCTL_PRIVCMD_MMAP_RESOURCE ioctl with num = 0 and addr = 0 in order to fetch the size of a specific resource. Add a shortcut to the default map resource path, since fetching the size requires no address to be passed in, and thus no VMA to setup. This is missing from the initial implementation, and causes issues when mapping resources that don't have fixed or known sizes. Signed-off-by: Roger Pau Monné Reviewed-by: Juergen Gross Tested-by: Andrew Cooper Cc: stable@vger.kernel.org # >= 4.18 Link: https://lore.kernel.org/r/20210112115358.23346-1-roger.pau@citrix.com Signed-off-by: Juergen Gross Signed-off-by: Greg Kroah-Hartman --- drivers/xen/privcmd.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -724,14 +724,15 @@ static long privcmd_ioctl_restrict(struc return 0; } -static long privcmd_ioctl_mmap_resource(struct file *file, void __user *udata) +static long privcmd_ioctl_mmap_resource(struct file *file, + struct privcmd_mmap_resource __user *udata) { struct privcmd_data *data = file->private_data; struct mm_struct *mm = current->mm; struct vm_area_struct *vma; struct privcmd_mmap_resource kdata; xen_pfn_t *pfns = NULL; - struct xen_mem_acquire_resource xdata; + struct xen_mem_acquire_resource xdata = { }; int rc; if (copy_from_user(&kdata, udata, sizeof(kdata))) @@ -741,6 +742,22 @@ static long privcmd_ioctl_mmap_resource( if (data->domid != DOMID_INVALID && data->domid != kdata.dom) return -EPERM; + /* Both fields must be set or unset */ + if (!!kdata.addr != !!kdata.num) + return -EINVAL; + + xdata.domid = kdata.dom; + xdata.type = kdata.type; + xdata.id = kdata.id; + + if (!kdata.addr && !kdata.num) { + /* Query the size of the resource. */ + rc = HYPERVISOR_memory_op(XENMEM_acquire_resource, &xdata); + if (rc) + return rc; + return __put_user(xdata.nr_frames, &udata->num); + } + down_write(&mm->mmap_sem); vma = find_vma(mm, kdata.addr); @@ -775,10 +792,6 @@ static long privcmd_ioctl_mmap_resource( } else vma->vm_private_data = PRIV_VMA_LOCKED; - memset(&xdata, 0, sizeof(xdata)); - xdata.domid = kdata.dom; - xdata.type = kdata.type; - xdata.id = kdata.id; xdata.frame = kdata.idx; xdata.nr_frames = kdata.num; set_xen_guest_handle(xdata.frame_list, pfns);