Skip to contentSkip to conversation

KVM: PPC: Check KVM_CREATE_SPAPR_TCE_64 parameters

PATCH Superseded Alexey Kardashevskiy 3 participants 3 messages May 14, 2018 – Jun 5, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 3/3 KVM: PPC: Check KVM_CREATE_SPAPR_TCE_64 parameters

Although it does not seem possible to break the host by passing bad parameters when creating a TCE table in KVM, it is still better to get an early clear indication of that than debugging weird effect this might bring.

This adds some sanity checks that the page size is 4KB..16GB as this is what the actual LoPAPR supports and that the window actually fits 64bit space.

---
 arch/powerpc/kvm/book3s_64_vio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/kvm/book3s_64_vio.c +2 -1
index 984f197..80ead38 100644
@@ -300,7 +300,8 @@ long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
 	int ret = -ENOMEM;
 	int i;
 
-	if (!args->size)
+	if (!args->size || args->page_shift < 12 || args->page_shift > 34 ||
+		(args->offset + args->size > (ULLONG_MAX >> args->page_shift)))
 		return -EINVAL;
 
 	size = _ALIGN_UP(args->size, PAGE_SIZE >> 3);
Signature · 1 line
2.11.0
Acked-by on v2 3/3
#1 lore raw
Quoted 19 lines · Alexey Kardashevskiy

Although it does not seem possible to break the host by passing bad parameters when creating a TCE table in KVM, it is still better to get an early clear indication of that than debugging weird effect this might bring.

This adds some sanity checks that the page size is 4KB..16GB as this is what the actual LoPAPR supports and that the window actually fits 64bit space.

---
 arch/powerpc/kvm/book3s_64_vio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/kvm/book3s_64_vio.c +0 -0
index 984f197..80ead38 100644

arch/powerpc/kvm/book3s_64_vio.c long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm, · line 304

Quoted 6 lines
arch/powerpc/kvm/book3s_64_vio.c +2 -1
@@ -300,7 +300,8 @@ long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
        int ret = -ENOMEM;
        int i;
 
-       if (!args->size)
+       if (!args->size || args->page_shift < 12 || args->page_shift > 34 ||
+               (args->offset + args->size > (ULLONG_MAX >> args->page_shift)))

Balbir

Reviewed-by on v2 3/3
#2 lore raw
In reply to Alexey Kardashevskiy
Quoted 10 lines · Alexey Kardashevskiy

Although it does not seem possible to break the host by passing bad parameters when creating a TCE table in KVM, it is still better to get an early clear indication of that than debugging weird effect this might bring.

This adds some sanity checks that the page size is 4KB..16GB as this is what the actual LoPAPR supports and that the window actually fits 64bit space.

Quoted 18 lines
---
 arch/powerpc/kvm/book3s_64_vio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/kvm/book3s_64_vio.c +2 -1
index 984f197..80ead38 100644
@@ -300,7 +300,8 @@ long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
 	int ret = -ENOMEM;
 	int i;
 
-	if (!args->size)
+	if (!args->size || args->page_shift < 12 || args->page_shift > 34 ||
+		(args->offset + args->size > (ULLONG_MAX >> args->page_shift)))
 		return -EINVAL;
 
 	size = _ALIGN_UP(args->size, PAGE_SIZE >> 3);
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson