From patchwork Sun Oct 22 07:48:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10021613 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 00E9F60224 for ; Sun, 22 Oct 2017 07:49:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6B1828613 for ; Sun, 22 Oct 2017 07:49:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9BCB2866B; Sun, 22 Oct 2017 07:49:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3054028613 for ; Sun, 22 Oct 2017 07:49:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=mkEZVcD/PYE5WAgnjL7S3yk4pqFZaCfu3IlTjthVhD8=; b=JbTRY7x7lbzfu2XRtZZkucIT8+ nSCY49U7Jx2znACEUIgjLP0g9Xt93OSepWIcFLCSnc2I7eAi4CeK0Q6kVoek1Z1oYOisMRfxJR1P2 +lzoTOxpsIaWBWzwz8WK0ISUCYS/2GB38VnzJeIlJwJjYwWGidLC9MXpaAWGSAk3YsULwGU9HbNtl FpvqhSzNAIVTJS3hg3b/XeVfsF4mGFRFbeLLyt/3DWOYVeeS3YJ1hYT7i++hTWcoqjOA7CYOb51TH fUPQB622WviMRl4pR6kwCk48q/6xQAUtKd6Eyd21eGzdkEll/LZ8sQp5AeP4nOV6sf7I8icHuqqpV QA++TXfw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e6B0L-00011I-Hr; Sun, 22 Oct 2017 07:49:05 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e6B0I-0000zf-9s for linux-arm-kernel@lists.infradead.org; Sun, 22 Oct 2017 07:49:04 +0000 Received: by mail-wm0-x242.google.com with SMTP id r68so4466024wmr.3 for ; Sun, 22 Oct 2017 00:48:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fZJxvLW7RbrngsSL+SaSWxMB1h+oMfLghP/oqCgSe/4=; b=NIOqIpHY1yYWPJiSoQkilzoPxO8Ocaz1h5VhEKhetV39VnRvlqO64WW8JyRrXUE9sy l/kg5+ZFRjdJmY3F5Fba7SvgJIxFiN/AoOxB36COMunYPw7T8iSkd3h7iJWxV6TouCDN LzE8PjO7WFglYQ8/XWjlqI+dGRb6ptnxeHZGg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fZJxvLW7RbrngsSL+SaSWxMB1h+oMfLghP/oqCgSe/4=; b=IFmFQWg9RoAjxlZu64YCcSbN+XYSjjwbs/U4HCnJ+I98xbY0COtUZuwNv/7x3ikbY6 dUYG2q7k3tVdWaY3E18dWYi1hY8a4LcgWxdRIkMFtNJ06rTGQeb5zDAGZkktu0VjIbfq TkIRFbPhhju81vS2tnBpGk0W5i0z2wOwWLzx5ckV971OaFEFQ/qvyU47qOfGdHOOdarC k/50Ak+dtwNmjeNs0dNeCP2qyuB99Cex7HqYpqb8b6MNVjlf0NGAovfgsCzmwpWwI/xK KFj04GQjjNzmAbDusPiK2kVB7J4jJFfC8iOd3aORczYOLtMslNPV0N3epz3P0a4V3civ zoeA== X-Gm-Message-State: AMCzsaVhHUOXAyyC5B4UcNURiFZqZ7NWkjxQ9MjAVGp/FBV53+Q2H2K6 pZ0AlJyrZqoIAeL/4fgXfTT6/78vzrE= X-Google-Smtp-Source: ABhQp+Sz/f4sV8FpwZvjlmVoilbLNyxClC4KF/6oVC0dNW2kxv4A08YSywEg2ZtBWE/nEl8gULMdZw== X-Received: by 10.80.162.103 with SMTP id 94mr12175066edl.159.1508658520525; Sun, 22 Oct 2017 00:48:40 -0700 (PDT) Received: from localhost.localdomain (xd93dd96b.cust.hiper.dk. [217.61.217.107]) by smtp.gmail.com with ESMTPSA id g45sm4128103eda.19.2017.10.22.00.48.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 Oct 2017 00:48:39 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu Subject: [PATCH v2] KVM: arm/arm64: Allow usercopy to vcpu->arch.ctxt and arm64 debug Date: Sun, 22 Oct 2017 09:48:36 +0200 Message-Id: <20171022074836.17728-1-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171020232525.7387-1-pbonzini@redhat.com> References: <20171020232525.7387-1-pbonzini@redhat.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171022_004902_507813_2F7C9A78 X-CRM114-Status: GOOD ( 12.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christoffer Dall , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We do direct useraccess copying to the kvm_cpu_context structure embedded in the kvm_vcpu_arch structure, and to the vcpu debug register state. Everything else (timer, PMU, vgic) goes through a temporary indirection. Fixing all accesses to kvm_cpu_context is massively invasive, and we'd like to avoid that, so we tell kvm_init_usercopy to whitelist accesses to out context structure. The debug system register accesses on arm64 are modified to work through an indirection instead. Signed-off-by: Christoffer Dall --- Changes since v1: - Use get_user() and put_user() instead of the implicit understanding that these will always be 64-bit values. arch/arm64/kvm/sys_regs.c | 44 ++++++++++++++++++++++++++++---------------- virt/kvm/arm/arm.c | 5 ++++- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 2e070d3baf9f..34b9e1734a3f 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -293,19 +293,22 @@ static bool trap_bvr(struct kvm_vcpu *vcpu, static int set_bvr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, const struct kvm_one_reg *reg, void __user *uaddr) { - __u64 *r = &vcpu->arch.vcpu_debug_state.dbg_bvr[rd->reg]; + __u64 __user *uval = uaddr; + __u64 r; - if (copy_from_user(r, uaddr, KVM_REG_SIZE(reg->id)) != 0) + if (get_user(r, uval)) return -EFAULT; + vcpu->arch.vcpu_debug_state.dbg_bvr[rd->reg] = r; return 0; } static int get_bvr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, const struct kvm_one_reg *reg, void __user *uaddr) { - __u64 *r = &vcpu->arch.vcpu_debug_state.dbg_bvr[rd->reg]; + __u64 r = vcpu->arch.vcpu_debug_state.dbg_bvr[rd->reg]; + __u64 __user *uval = uaddr; - if (copy_to_user(uaddr, r, KVM_REG_SIZE(reg->id)) != 0) + if (put_user(r, uval)) return -EFAULT; return 0; } @@ -335,10 +338,12 @@ static bool trap_bcr(struct kvm_vcpu *vcpu, static int set_bcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, const struct kvm_one_reg *reg, void __user *uaddr) { - __u64 *r = &vcpu->arch.vcpu_debug_state.dbg_bcr[rd->reg]; + __u64 __user *uval = uaddr; + __u64 r; - if (copy_from_user(r, uaddr, KVM_REG_SIZE(reg->id)) != 0) + if (get_user(r, uval)) return -EFAULT; + vcpu->arch.vcpu_debug_state.dbg_bcr[rd->reg] = r; return 0; } @@ -346,9 +351,10 @@ static int set_bcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, static int get_bcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, const struct kvm_one_reg *reg, void __user *uaddr) { - __u64 *r = &vcpu->arch.vcpu_debug_state.dbg_bcr[rd->reg]; + __u64 r = vcpu->arch.vcpu_debug_state.dbg_bcr[rd->reg]; + __u64 __user *uval = uaddr; - if (copy_to_user(uaddr, r, KVM_REG_SIZE(reg->id)) != 0) + if (put_user(r, uval)) return -EFAULT; return 0; } @@ -379,19 +385,22 @@ static bool trap_wvr(struct kvm_vcpu *vcpu, static int set_wvr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, const struct kvm_one_reg *reg, void __user *uaddr) { - __u64 *r = &vcpu->arch.vcpu_debug_state.dbg_wvr[rd->reg]; + __u64 __user *uval = uaddr; + __u64 r; - if (copy_from_user(r, uaddr, KVM_REG_SIZE(reg->id)) != 0) + if (get_user(r, uval)) return -EFAULT; + vcpu->arch.vcpu_debug_state.dbg_wvr[rd->reg] = r; return 0; } static int get_wvr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, const struct kvm_one_reg *reg, void __user *uaddr) { - __u64 *r = &vcpu->arch.vcpu_debug_state.dbg_wvr[rd->reg]; + __u64 r = vcpu->arch.vcpu_debug_state.dbg_wvr[rd->reg]; + __u64 __user *uval = uaddr; - if (copy_to_user(uaddr, r, KVM_REG_SIZE(reg->id)) != 0) + if (put_user(r, uval)) return -EFAULT; return 0; } @@ -421,19 +430,22 @@ static bool trap_wcr(struct kvm_vcpu *vcpu, static int set_wcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, const struct kvm_one_reg *reg, void __user *uaddr) { - __u64 *r = &vcpu->arch.vcpu_debug_state.dbg_wcr[rd->reg]; + __u64 __user *uval = uaddr; + __u64 r; - if (copy_from_user(r, uaddr, KVM_REG_SIZE(reg->id)) != 0) + if (get_user(r, uval)) return -EFAULT; + vcpu->arch.vcpu_debug_state.dbg_wcr[rd->reg] = r; return 0; } static int get_wcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, const struct kvm_one_reg *reg, void __user *uaddr) { - __u64 *r = &vcpu->arch.vcpu_debug_state.dbg_wcr[rd->reg]; + __u64 r = vcpu->arch.vcpu_debug_state.dbg_wcr[rd->reg]; + __u64 __user *uval = uaddr; - if (copy_to_user(uaddr, r, KVM_REG_SIZE(reg->id)) != 0) + if (put_user(r, uval)) return -EFAULT; return 0; } diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index b9f68e4add71..639e388678ff 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -1502,7 +1502,10 @@ void kvm_arch_exit(void) static int arm_init(void) { - int rc = kvm_init(NULL, sizeof(struct kvm_vcpu), 0, THIS_MODULE); + int rc = kvm_init_usercopy(NULL, sizeof(struct kvm_vcpu), 0, + offsetof(struct kvm_vcpu_arch, ctxt), + sizeof_field(struct kvm_vcpu_arch, ctxt), + THIS_MODULE); return rc; }