Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp505583yba; Mon, 1 Apr 2019 10:38:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqwibxckeV/JgjNcP28LmGLn2aMLAx+nj+OlQtebfRVht/HZF992YkCv/HftaSCxYTWge0jQ X-Received: by 2002:a63:7e10:: with SMTP id z16mr8711575pgc.40.1554140330237; Mon, 01 Apr 2019 10:38:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554140330; cv=none; d=google.com; s=arc-20160816; b=M0lcjHPGdlVYS4H9AormT7hOGNXhgNdjDIIfYeHZT8u/cFRCHHdguTUXlZLjBwyRyW TG3kqfDrYbkb15mXP8r6NH7zqH25dwyyMvCTXMnzC49rIuOVRcAenIR0JfzNkMmSU68r qc6aV3aADDVriuhtVmr6KttglYt+Yv9JvGudlTBaNOt3rqq0r8qir4LhYYU5n/4XudHm uH1nucQPnhx0/UrZXGAEREj4Z7ufCTftiVfzgAhVmtS5KsL2pGOeoyraT4U0zWF4dEMx rAlN+vgBwoq+YiGaLHrCt6lE8+MGmVbRR3GQEqmpcPqe3F78FLTsIqEiEwuBgmOS6dQp e2sQ== 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:dkim-signature; bh=fpYfJDtal6q8nYGDQ/JKmHmlqOJDAFZ0psoNVLi0vIs=; b=lBgSDfVixTiV5x0JVtc93VRcBYsYcM1NqU4VTzzmd0rzqbH5iwYkzLbEfCB/M7sHBC ZF+JZAaJKcYfRMGZHV7qiIa1eFQMQMibIjA+K4fCqrCZLjCHglRdEn9meZVH3kFcUH6O TOyrXPS+B8UXc4jvQh/UOhEc9vXfF7xkNhLIbiiGt2FbXaKz8OBKUBRB0FNrswqCENxu Knxgdt1YS8p4Ukl0JNtTw3VZZY3iifgAbPCIFb7e8vGFkPu45VfC4KQ91KdzrtAoFebK ntaYS1+33yZbyYLYE+s+Dyl3mOmiH1YMbVwJ/aVt1zj12tx6nTKupIB+6L3Cv6ZS/kpP Vn0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2VqEUBno; 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 p6si9003029plo.4.2019.04.01.10.38.35; Mon, 01 Apr 2019 10:38: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; dkim=pass header.i=@kernel.org header.s=default header.b=2VqEUBno; 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 S2388064AbfDARgl (ORCPT + 99 others); Mon, 1 Apr 2019 13:36:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:48582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387697AbfDARgj (ORCPT ); Mon, 1 Apr 2019 13:36:39 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1816B2070B; Mon, 1 Apr 2019 17:36:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554140198; bh=9Q+YaXajQC9ZlcbN+Q46N53ClCYkrHNQ3aUFfz1P06A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2VqEUBnowf9rjwfMbPBxXLQECNf7wP/SI5vaC4irCRY03Lc0HOrBL5g0P/bWAaZgf dh0pJgLgrTUDUbKkH2zPAKSpSmF3wb3kBg9SKNd6y294GX1JDMw4PTs5Ohhd56oiLt 7EBPh6w6AGfcMAJK5sKBYAUwH/YmmT1FCakLQRr4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Paolo Bonzini Subject: [PATCH 4.4 126/131] KVM: Reject device ioctls from processes other than the VMs creator Date: Mon, 1 Apr 2019 19:03:16 +0200 Message-Id: <20190401170101.968728808@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190401170051.645954551@linuxfoundation.org> References: <20190401170051.645954551@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sean Christopherson commit ddba91801aeb5c160b660caed1800eb3aef403f8 upstream. KVM's API requires thats ioctls must be issued from the same process that created the VM. In other words, userspace can play games with a VM's file descriptors, e.g. fork(), SCM_RIGHTS, etc..., but only the creator can do anything useful. Explicitly reject device ioctls that are issued by a process other than the VM's creator, and update KVM's API documentation to extend its requirements to device ioctls. Fixes: 852b6d57dc7f ("kvm: add device control API") Cc: Signed-off-by: Sean Christopherson Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- Documentation/virtual/kvm/api.txt | 16 +++++++++++----- virt/kvm/kvm_main.c | 3 +++ 2 files changed, 14 insertions(+), 5 deletions(-) --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt @@ -13,7 +13,7 @@ of a virtual machine. The ioctls belong - VM ioctls: These query and set attributes that affect an entire virtual machine, for example memory layout. In addition a VM ioctl is used to - create virtual cpus (vcpus). + create virtual cpus (vcpus) and devices. Only run VM ioctls from the same process (address space) that was used to create the VM. @@ -24,6 +24,11 @@ of a virtual machine. The ioctls belong Only run vcpu ioctls from the same thread that was used to create the vcpu. + - device ioctls: These query and set attributes that control the operation + of a single device. + + device ioctls must be issued from the same process (address space) that + was used to create the VM. 2. File descriptors ------------------- @@ -32,10 +37,11 @@ The kvm API is centered around file desc open("/dev/kvm") obtains a handle to the kvm subsystem; this handle can be used to issue system ioctls. A KVM_CREATE_VM ioctl on this handle will create a VM file descriptor which can be used to issue VM -ioctls. A KVM_CREATE_VCPU ioctl on a VM fd will create a virtual cpu -and return a file descriptor pointing to it. Finally, ioctls on a vcpu -fd can be used to control the vcpu, including the important task of -actually running guest code. +ioctls. A KVM_CREATE_VCPU or KVM_CREATE_DEVICE ioctl on a VM fd will +create a virtual cpu or device and return a file descriptor pointing to +the new resource. Finally, ioctls on a vcpu or device fd can be used +to control the vcpu or device. For vcpus, this includes the important +task of actually running guest code. In general file descriptors can be migrated among processes by means of fork() and the SCM_RIGHTS facility of unix domain socket. These --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2611,6 +2611,9 @@ static long kvm_device_ioctl(struct file { struct kvm_device *dev = filp->private_data; + if (dev->kvm->mm != current->mm) + return -EIO; + switch (ioctl) { case KVM_SET_DEVICE_ATTR: return kvm_device_ioctl_attr(dev, dev->ops->set_attr, arg);