Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1916992pxb; Thu, 16 Sep 2021 20:11:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziWsmcLQOIRnEQV75hK6CqK5Id7BLeZna15eix2uCrygwx2JqpVApghJDSgWZEla8NJuZ5 X-Received: by 2002:a17:906:a3c3:: with SMTP id ca3mr9860963ejb.337.1631848259836; Thu, 16 Sep 2021 20:10:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631848259; cv=none; d=google.com; s=arc-20160816; b=bcaCAjSosNfBSllmomiyOSy1uOIfHxnLCfBfy/DnUSONICUJiO9A9WEb64mSLNTL8H ttfJlWK9HL4KuOue0zHNz5XXlFezvc2tKnkl2Q2R2Q7CfA6ABy93nM2klh3odE3NWpi5 BkpMujoliJdl9VjNptIO5fpUyR1C78ofmHITig7sbeFSiswdr0CTLTJPz+FDN+5sghUU F1kanj16F9imo2G7Lan6yi4YwZCJ8pX9AwUa7zhW4sluBNjmsTtse7iFC4xOk+3uWMAC 5nBSSMjhTrvCZ+TlUNRxyOtlFSGhmAU1K5Igebf3hW2oG+2fFT69iShQ+B/ch0vPdi23 IJdQ== 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=3PB1ipX/SYtsihbp7UwYaEkXspY1bfhekqj8Yzt9rQg=; b=lKs8ihwhvnku8hUt1UTQpOziq81bAFOUyGDIAtSNb+Ep+2HsKQ37Ka5EN8Vfs7HS6d BpN2Mr5hjhNleIbjxPt+FmJKfK3Q2Ub12x3aBSSvvMNX0X8t7k+KPgWsYBbnW/cvyiaE IVX9A17woxg6pOLfzuBIT58bDJDZoBDX8thPHuGun+A8TJhAyFgI3sPMl0UMglY9gWCs Hbu4rWBfy0eCQ6x8hKdnbHzwEBXMZzznp94uA9e8zeuElNh8AMBy5gm9pK8h23kFFGjS Pwg1tZj8z+JBb3jCuiGNniHlWK6VyRfINqZ9FGKCaa/bkgXEZnfbPiVuQyzRmOnjqyif KTBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=X6pvAoad; 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 p15si6895616edj.97.2021.09.16.20.10.35; Thu, 16 Sep 2021 20:10:59 -0700 (PDT) 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=X6pvAoad; 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 S236366AbhIPR26 (ORCPT + 99 others); Thu, 16 Sep 2021 13:28:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:43518 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351935AbhIPRUA (ORCPT ); Thu, 16 Sep 2021 13:20:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C5D1160F50; Thu, 16 Sep 2021 16:41:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631810499; bh=VVPSPpRvmn4ZsitzR1THjzMYO1QDw/mTwAOXH1M8shM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X6pvAoadiT2HMyGH1JMnowbEyZv5/+jEzt/rWjAgX2EwMuF+f+X4Q4lFtLj592vYJ /2acSwE6aR8G2lpxBxtYZyyZH+GBqLinLFsEbBmZLDIFAQ/fMOkJk0YfhbIHMlRArp L9gXDQ/HTc87OAbF77LLIDD1PZ0DqcO6swaNZVvQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Fabiano Rosas , Nicholas Piggin , Michael Ellerman , Sasha Levin Subject: [PATCH 5.14 131/432] KVM: PPC: Book3S HV: Fix copy_tofrom_guest routines Date: Thu, 16 Sep 2021 17:58:00 +0200 Message-Id: <20210916155815.204407521@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155810.813340753@linuxfoundation.org> References: <20210916155810.813340753@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: Fabiano Rosas [ Upstream commit 5d7d6dac8fe99ed59eee2300e4a03370f94d5222 ] The __kvmhv_copy_tofrom_guest_radix function was introduced along with nested HV guest support. It uses the platform's Radix MMU quadrants to provide a nested hypervisor with fast access to its nested guests memory (H_COPY_TOFROM_GUEST hypercall). It has also since been added as a fast path for the kvmppc_ld/st routines which are used during instruction emulation. The commit def0bfdbd603 ("powerpc: use probe_user_read() and probe_user_write()") changed the low level copy function from raw_copy_from_user to probe_user_read, which adds a check to access_ok. In powerpc that is: static inline bool __access_ok(unsigned long addr, unsigned long size) { return addr < TASK_SIZE_MAX && size <= TASK_SIZE_MAX - addr; } and TASK_SIZE_MAX is 0x0010000000000000UL for 64-bit, which means that setting the two MSBs of the effective address (which correspond to the quadrant) now cause access_ok to reject the access. This was not caught earlier because the most common code path via kvmppc_ld/st contains a fallback (kvm_read_guest) that is likely to succeed for L1 guests. For nested guests there is no fallback. Another issue is that probe_user_read (now __copy_from_user_nofault) does not return the number of bytes not copied in case of failure, so the destination memory is not being cleared anymore in kvmhv_copy_from_guest_radix: ret = kvmhv_copy_tofrom_guest_radix(vcpu, eaddr, to, NULL, n); if (ret > 0) <-- always false! memset(to + (n - ret), 0, ret); This patch fixes both issues by skipping access_ok and open-coding the low level __copy_to/from_user_inatomic. Fixes: def0bfdbd603 ("powerpc: use probe_user_read() and probe_user_write()") Signed-off-by: Fabiano Rosas Reviewed-by: Nicholas Piggin Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20210805212616.2641017-2-farosas@linux.ibm.com Signed-off-by: Sasha Levin --- arch/powerpc/kvm/book3s_64_mmu_radix.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c b/arch/powerpc/kvm/book3s_64_mmu_radix.c index b5905ae4377c..44eb7b1ef289 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_radix.c +++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c @@ -65,10 +65,12 @@ unsigned long __kvmhv_copy_tofrom_guest_radix(int lpid, int pid, } isync(); + pagefault_disable(); if (is_load) - ret = copy_from_user_nofault(to, (const void __user *)from, n); + ret = __copy_from_user_inatomic(to, (const void __user *)from, n); else - ret = copy_to_user_nofault((void __user *)to, from, n); + ret = __copy_to_user_inatomic((void __user *)to, from, n); + pagefault_enable(); /* switch the pid first to avoid running host with unallocated pid */ if (quadrant == 1 && pid != old_pid) -- 2.30.2