Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1764323pxb; Thu, 16 Sep 2021 15:13:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzX+dn3nLYohT0wzZ91M7edVM/MIDEtdC6ML3Far77yrjGuSgg9vKWJ6bHaKF5KwM8EQHz X-Received: by 2002:a05:6e02:1b84:: with SMTP id h4mr5640095ili.30.1631830396664; Thu, 16 Sep 2021 15:13:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631830396; cv=none; d=google.com; s=arc-20160816; b=jiEdIqDbHtOehF3/Cra8a0TTkow1pDVqihyMacfaW0+6nT5duPoS3pwMrhrdaimrk/ I7YlAkDlMY7hae6KWllKddigFpscb1mIhLeKPbBtdCGm6OLWDwM78RlIS1XIeo8IP8t0 jYZH4eC4eW5/t7GrcTs4bIxuMi/xCTHq+CapQBuw/bcrkyN+iPLoHlBLh3BVKAX/79mo 0YC8z2iyqr82tyWBTlwT4hmxWDU1407h8M2r0gTibijKvOsxVLD6+mYhUIMNQNDg7nkz Go7XxzF3JuXsUnTO0YCUvBMVMbCxp5vFPOo12EAF43LHsq8mteI7JVWGVipKOOtTg+Mu U21w== 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=F4Q9t9rA23GdyUwwbQ7Z8Y7hl3DRlARDFYMrunLrTJ0=; b=hOGM48Q3fEPsffSu6vuOiiEUUzHjr9TvC6uciG9Nb4v48BLYMpiwH78ehPGNxZiMPz OEURBR3aS7wJpyfKhLww2Ks1D5qVSXCbTnEX9FUXltIDvDcndUMGlpQlrgOFpWzPrRYS MRWlSewFXjpLk/GCSy7p7MdPf9dNouzsGHq1ZV8w0DHsFrEEdQQS8rdh2LT1prT9UaRb g7FyepDhb6KTh4S3wLVZTDc994lgniMFswSvDlP0I+dNVySkeMSv/uhwGi3HntrNrxvL A+LZ8KYeplKLNioKo0H4U0TEgXxDxcHqwCed0lrd8w+3W+DM9tpMDRI7Y/Y6NgICOOzo EKrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="N/7TPnop"; 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 m8si3409342ila.156.2021.09.16.15.13.05; Thu, 16 Sep 2021 15:13:16 -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="N/7TPnop"; 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 S1343921AbhIPQoV (ORCPT + 99 others); Thu, 16 Sep 2021 12:44:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:51356 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242294AbhIPQhO (ORCPT ); Thu, 16 Sep 2021 12:37:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6606761407; Thu, 16 Sep 2021 16:22:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631809331; bh=SGzqUnpgDK46LkHVv3zcFeFk5dH3PCp7IRB9mX6et10=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N/7TPnop98GWHe1ZuXaBZdYmj43DSy80RdMGOJBKqbJRBCTfzdbsOGEh+Sz2a4YHw zmg6qlKt0vegJ7mJSKPPsfB5oWxJs07LRE1RXkLwRMalwuASepVgOVLVW43ZN1QW1O VY17rMhZozHQzxJiAGBj74UPUAVe9RmtJoL2j1mE= 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.13 116/380] KVM: PPC: Book3S HV: Fix copy_tofrom_guest routines Date: Thu, 16 Sep 2021 17:57:53 +0200 Message-Id: <20210916155807.984471525@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155803.966362085@linuxfoundation.org> References: <20210916155803.966362085@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 d909c069363e..e7924664a944 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_radix.c +++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c @@ -64,10 +64,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