public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 03/10] kvmclock: Use free_decrypted_pages()
       [not found] <20231017202505.340906-1-rick.p.edgecombe@intel.com>
@ 2023-10-17 20:24 ` Rick Edgecombe
  2023-10-18  5:20   ` Kuppuswamy Sathyanarayanan
  0 siblings, 1 reply; 3+ messages in thread
From: Rick Edgecombe @ 2023-10-17 20:24 UTC (permalink / raw)
  To: x86, tglx, mingo, bp, dave.hansen, hpa, luto, peterz,
	kirill.shutemov, elena.reshetova, isaku.yamahata, seanjc,
	Michael Kelley, thomas.lendacky, decui,
	sathyanarayanan.kuppuswamy, linux-mm, linux-kernel, linux-s390
  Cc: rick.p.edgecombe, Paolo Bonzini, Wanpeng Li, Vitaly Kuznetsov,
	kvm

On TDX it is possible for the untrusted host to cause
set_memory_encrypted() or set_memory_decrypted() to fail such that an
error is returned and the resulting memory is shared. Callers need to take
care to handle these errors to avoid returning decrypted (shared) memory to
the page allocator, which could lead to functional or security issues.

Kvmclock could free decrypted/shared pages if set_memory_decrypted() fails.
Use the recently added free_decrypted_pages() to avoid this.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Wanpeng Li <wanpengli@tencent.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: kvm@vger.kernel.org
Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
---
 arch/x86/kernel/kvmclock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
index fb8f52149be9..587b159c4e53 100644
--- a/arch/x86/kernel/kvmclock.c
+++ b/arch/x86/kernel/kvmclock.c
@@ -227,7 +227,7 @@ static void __init kvmclock_init_mem(void)
 		r = set_memory_decrypted((unsigned long) hvclock_mem,
 					 1UL << order);
 		if (r) {
-			__free_pages(p, order);
+			free_decrypted_pages((unsigned long)hvclock_mem, order);
 			hvclock_mem = NULL;
 			pr_warn("kvmclock: set_memory_decrypted() failed. Disabling\n");
 			return;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 03/10] kvmclock: Use free_decrypted_pages()
  2023-10-17 20:24 ` [PATCH 03/10] kvmclock: Use free_decrypted_pages() Rick Edgecombe
@ 2023-10-18  5:20   ` Kuppuswamy Sathyanarayanan
  2023-10-18 15:57     ` Edgecombe, Rick P
  0 siblings, 1 reply; 3+ messages in thread
From: Kuppuswamy Sathyanarayanan @ 2023-10-18  5:20 UTC (permalink / raw)
  To: Rick Edgecombe, x86, tglx, mingo, bp, dave.hansen, hpa, luto,
	peterz, kirill.shutemov, elena.reshetova, isaku.yamahata, seanjc,
	Michael Kelley, thomas.lendacky, decui, linux-mm, linux-kernel,
	linux-s390
  Cc: Paolo Bonzini, Wanpeng Li, Vitaly Kuznetsov, kvm



On 10/17/2023 1:24 PM, Rick Edgecombe wrote:
> On TDX it is possible for the untrusted host to cause
> set_memory_encrypted() or set_memory_decrypted() to fail such that an
> error is returned and the resulting memory is shared. Callers need to take
> care to handle these errors to avoid returning decrypted (shared) memory to
> the page allocator, which could lead to functional or security issues.
> 
> Kvmclock could free decrypted/shared pages if set_memory_decrypted() fails.
> Use the recently added free_decrypted_pages() to avoid this.
> 
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Wanpeng Li <wanpengli@tencent.com>
> Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
> Cc: kvm@vger.kernel.org
> Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
> ---

Since it a fix, do you want to add Fixes tag?

Otherwise, it looks good to me.

Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>


>  arch/x86/kernel/kvmclock.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
> index fb8f52149be9..587b159c4e53 100644
> --- a/arch/x86/kernel/kvmclock.c
> +++ b/arch/x86/kernel/kvmclock.c
> @@ -227,7 +227,7 @@ static void __init kvmclock_init_mem(void)
>  		r = set_memory_decrypted((unsigned long) hvclock_mem,
>  					 1UL << order);
>  		if (r) {
> -			__free_pages(p, order);
> +			free_decrypted_pages((unsigned long)hvclock_mem, order);
>  			hvclock_mem = NULL;
>  			pr_warn("kvmclock: set_memory_decrypted() failed. Disabling\n");
>  			return;

-- 
Sathyanarayanan Kuppuswamy
Linux Kernel Developer

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 03/10] kvmclock: Use free_decrypted_pages()
  2023-10-18  5:20   ` Kuppuswamy Sathyanarayanan
@ 2023-10-18 15:57     ` Edgecombe, Rick P
  0 siblings, 0 replies; 3+ messages in thread
From: Edgecombe, Rick P @ 2023-10-18 15:57 UTC (permalink / raw)
  To: Lutomirski, Andy, linux-mm@kvack.org, dave.hansen@linux.intel.com,
	thomas.lendacky@amd.com, Reshetova, Elena,
	kirill.shutemov@linux.intel.com, mingo@redhat.com,
	Christopherson,, Sean, linux-kernel@vger.kernel.org,
	tglx@linutronix.de, Cui, Dexuan, Yamahata, Isaku,
	mikelley@microsoft.com, hpa@zytor.com, peterz@infradead.org,
	bp@alien8.de, linux-s390@vger.kernel.org,
	sathyanarayanan.kuppuswamy@linux.intel.com, x86@kernel.org
  Cc: kvm@vger.kernel.org, pbonzini@redhat.com, wanpengli@tencent.com,
	vkuznets@redhat.com

On Tue, 2023-10-17 at 22:20 -0700, Kuppuswamy Sathyanarayanan wrote:
> 
> 
> On 10/17/2023 1:24 PM, Rick Edgecombe wrote:
> > On TDX it is possible for the untrusted host to cause
> > set_memory_encrypted() or set_memory_decrypted() to fail such that
> > an
> > error is returned and the resulting memory is shared. Callers need
> > to take
> > care to handle these errors to avoid returning decrypted (shared)
> > memory to
> > the page allocator, which could lead to functional or security
> > issues.
> > 
> > Kvmclock could free decrypted/shared pages if
> > set_memory_decrypted() fails.
> > Use the recently added free_decrypted_pages() to avoid this.
> > 
> > Cc: Paolo Bonzini <pbonzini@redhat.com>
> > Cc: Wanpeng Li <wanpengli@tencent.com>
> > Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
> > Cc: kvm@vger.kernel.org
> > Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
> > ---
> 
> Since it a fix, do you want to add Fixes tag?
> 
> Otherwise, it looks good to me.
> 
> Reviewed-by: Kuppuswamy Sathyanarayanan
> <sathyanarayanan.kuppuswamy@linux.intel.com>

Thanks. Yes, the thinking was to mark all these for stable, but some
patches are still RFC for this version. I'll add it for all non-RFC
ones in the next version.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-10-18 15:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20231017202505.340906-1-rick.p.edgecombe@intel.com>
2023-10-17 20:24 ` [PATCH 03/10] kvmclock: Use free_decrypted_pages() Rick Edgecombe
2023-10-18  5:20   ` Kuppuswamy Sathyanarayanan
2023-10-18 15:57     ` Edgecombe, Rick P

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox