[kernel,v2,3/3] KVM: PPC: Check KVM_CREATE_SPAPR_TCE_64 parameters

Message ID 20180514100029.32910-4-aik@ozlabs.ru
State Awaiting Upstream
Headers show
Series
  • KVM: PPC: Allow backing bigger guest IOMMU pages with smaller physical
Related show

Commit Message

Alexey Kardashevskiy May 14, 2018, 10 a.m.
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.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
 arch/powerpc/kvm/book3s_64_vio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Balbir Singh May 15, 2018, 5:37 a.m. | #1
On Mon, May 14, 2018 at 8:00 PM, Alexey Kardashevskiy <aik@ozlabs.ru> wrote:
> 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.
>
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> ---
>  arch/powerpc/kvm/book3s_64_vio.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/kvm/book3s_64_vio.c b/arch/powerpc/kvm/book3s_64_vio.c
> index 984f197..80ead38 100644
> --- a/arch/powerpc/kvm/book3s_64_vio.c
> +++ b/arch/powerpc/kvm/book3s_64_vio.c
> @@ -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)))

Acked-by: Balbir Singh <bsingharora@gmail.com>

Balbir
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/arch/powerpc/kvm/book3s_64_vio.c b/arch/powerpc/kvm/book3s_64_vio.c
index 984f197..80ead38 100644
--- a/arch/powerpc/kvm/book3s_64_vio.c
+++ b/arch/powerpc/kvm/book3s_64_vio.c
@@ -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);