linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: x86: do not pass poisoned hva to __kvm_set_memory_region
@ 2020-06-11 18:01 Paolo Bonzini
  2020-06-11 20:14 ` Maxim Levitsky
  0 siblings, 1 reply; 2+ messages in thread
From: Paolo Bonzini @ 2020-06-11 18:01 UTC (permalink / raw)
  To: linux-kernel, kvm; +Cc: Maxim Levitsky

__kvm_set_memory_region does not use the hva at all, so trying to
catch use-after-delete is pointless and, worse, it fails access_ok
now that we apply it to all memslots including private kernel ones.
This fixes an AVIC regression.

Fixes: 09d952c971a5 ("KVM: check userspace_addr for all memslots", 2020-06-01)
Reported-by: Maxim Levitsky <mlevitsk@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/kvm/x86.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 290784ba63e4..00c88c2f34e4 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -9951,13 +9951,8 @@ int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size)
 		if (!slot || !slot->npages)
 			return 0;
 
-		/*
-		 * Stuff a non-canonical value to catch use-after-delete.  This
-		 * ends up being 0 on 32-bit KVM, but there's no better
-		 * alternative.
-		 */
-		hva = (unsigned long)(0xdeadull << 48);
 		old_npages = slot->npages;
+		hva = 0;
 	}
 
 	for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) {
-- 
2.26.2


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

* Re: [PATCH] KVM: x86: do not pass poisoned hva to __kvm_set_memory_region
  2020-06-11 18:01 [PATCH] KVM: x86: do not pass poisoned hva to __kvm_set_memory_region Paolo Bonzini
@ 2020-06-11 20:14 ` Maxim Levitsky
  0 siblings, 0 replies; 2+ messages in thread
From: Maxim Levitsky @ 2020-06-11 20:14 UTC (permalink / raw)
  To: Paolo Bonzini, linux-kernel, kvm

On Thu, 2020-06-11 at 14:01 -0400, Paolo Bonzini wrote:
> __kvm_set_memory_region does not use the hva at all, so trying to
> catch use-after-delete is pointless and, worse, it fails access_ok
> now that we apply it to all memslots including private kernel ones.
> This fixes an AVIC regression.
> 
> Fixes: 09d952c971a5 ("KVM: check userspace_addr for all memslots", 2020-06-01)
> Reported-by: Maxim Levitsky <mlevitsk@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  arch/x86/kvm/x86.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 290784ba63e4..00c88c2f34e4 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -9951,13 +9951,8 @@ int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size)
>  		if (!slot || !slot->npages)
>  			return 0;
>  
> -		/*
> -		 * Stuff a non-canonical value to catch use-after-delete.  This
> -		 * ends up being 0 on 32-bit KVM, but there's no better
> -		 * alternative.
> -		 */
> -		hva = (unsigned long)(0xdeadull << 48);
>  		old_npages = slot->npages;
> +		hva = 0;
>  	}
>  
>  	for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) {


Under assumption that we can assume that access_ok(0,0) is safe to assume
to be always true:
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>

I also tested exactly this solution when triaging this bug and it works,
but I wasn't sure that this is the correct solution.

Best regards,
	Maxim Levitsky




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

end of thread, other threads:[~2020-06-11 20:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-11 18:01 [PATCH] KVM: x86: do not pass poisoned hva to __kvm_set_memory_region Paolo Bonzini
2020-06-11 20:14 ` Maxim Levitsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).