* [PATCH] Fix NULL dereference in gfn_to_hva_prot()
@ 2013-10-01 16:58 Gleb Natapov
2013-10-01 17:03 ` Paolo Bonzini
0 siblings, 1 reply; 2+ messages in thread
From: Gleb Natapov @ 2013-10-01 16:58 UTC (permalink / raw)
To: kvm; +Cc: pbonzini
gfn_to_memslot() can return NULL or invalid slot. We need to check slot
validity before accessing it.
Signed-off-by: Gleb Natapov <gleb@redhat.com>
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 979bff4..a9dd682 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1064,10 +1064,12 @@ EXPORT_SYMBOL_GPL(gfn_to_hva);
unsigned long gfn_to_hva_prot(struct kvm *kvm, gfn_t gfn, bool *writable)
{
struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn);
- if (writable)
+ unsigned long hva = __gfn_to_hva_many(slot, gfn, NULL, false);
+
+ if (!kvm_is_error_hva(hva) && writable)
*writable = !memslot_is_readonly(slot);
- return __gfn_to_hva_many(gfn_to_memslot(kvm, gfn), gfn, NULL, false);
+ return hva;
}
static int kvm_read_hva(void *data, void __user *hva, int len)
--
Gleb.
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix NULL dereference in gfn_to_hva_prot()
2013-10-01 16:58 [PATCH] Fix NULL dereference in gfn_to_hva_prot() Gleb Natapov
@ 2013-10-01 17:03 ` Paolo Bonzini
0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2013-10-01 17:03 UTC (permalink / raw)
To: Gleb Natapov; +Cc: kvm
Il 01/10/2013 18:58, Gleb Natapov ha scritto:
> gfn_to_memslot() can return NULL or invalid slot. We need to check slot
> validity before accessing it.
>
> Signed-off-by: Gleb Natapov <gleb@redhat.com>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 979bff4..a9dd682 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -1064,10 +1064,12 @@ EXPORT_SYMBOL_GPL(gfn_to_hva);
> unsigned long gfn_to_hva_prot(struct kvm *kvm, gfn_t gfn, bool *writable)
> {
> struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn);
> - if (writable)
> + unsigned long hva = __gfn_to_hva_many(slot, gfn, NULL, false);
> +
> + if (!kvm_is_error_hva(hva) && writable)
> *writable = !memslot_is_readonly(slot);
>
> - return __gfn_to_hva_many(gfn_to_memslot(kvm, gfn), gfn, NULL, false);
> + return hva;
> }
>
> static int kvm_read_hva(void *data, void __user *hva, int len)
> --
> Gleb.
>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-10-01 17:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-01 16:58 [PATCH] Fix NULL dereference in gfn_to_hva_prot() Gleb Natapov
2013-10-01 17:03 ` Paolo Bonzini
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).