All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] KVM: SVM: prevent DBG_DECRYPT and DBG_ENCRYPT overflow
@ 2019-03-25 18:47 David Rientjes
  2019-03-28 13:58 ` Singh, Brijesh
  2019-04-05 18:50 ` Paolo Bonzini
  0 siblings, 2 replies; 4+ messages in thread
From: David Rientjes @ 2019-03-25 18:47 UTC (permalink / raw)
  To: Brijesh Singh, Joerg Roedel, Paolo Bonzini, Radim Krčmář
  Cc: Borislav Petkov, x86, kvm, linux-kernel

This ensures that the address and length provided to DBG_DECRYPT and
DBG_ENCRYPT do not cause an overflow.

At the same time, pass the actual number of pages pinned in memory to
sev_unpin_memory() as a cleanup.

Reported-by: Cfir Cohen <cfir@google.com>
Signed-off-by: David Rientjes <rientjes@google.com>
---
 arch/x86/kvm/svm.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -6799,7 +6799,8 @@ static int sev_dbg_crypt(struct kvm *kvm, struct kvm_sev_cmd *argp, bool dec)
 	struct page **src_p, **dst_p;
 	struct kvm_sev_dbg debug;
 	unsigned long n;
-	int ret, size;
+	unsigned int size;
+	int ret;
 
 	if (!sev_guest(kvm))
 		return -ENOTTY;
@@ -6807,6 +6808,11 @@ static int sev_dbg_crypt(struct kvm *kvm, struct kvm_sev_cmd *argp, bool dec)
 	if (copy_from_user(&debug, (void __user *)(uintptr_t)argp->data, sizeof(debug)))
 		return -EFAULT;
 
+	if (!debug.len || debug.src_uaddr + debug.len < debug.src_uaddr)
+		return -EINVAL;
+	if (!debug.dst_uaddr)
+		return -EINVAL;
+
 	vaddr = debug.src_uaddr;
 	size = debug.len;
 	vaddr_end = vaddr + size;
@@ -6857,8 +6863,8 @@ static int sev_dbg_crypt(struct kvm *kvm, struct kvm_sev_cmd *argp, bool dec)
 						     dst_vaddr,
 						     len, &argp->error);
 
-		sev_unpin_memory(kvm, src_p, 1);
-		sev_unpin_memory(kvm, dst_p, 1);
+		sev_unpin_memory(kvm, src_p, n);
+		sev_unpin_memory(kvm, dst_p, n);
 
 		if (ret)
 			goto err;

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

* Re: [patch] KVM: SVM: prevent DBG_DECRYPT and DBG_ENCRYPT overflow
  2019-03-25 18:47 [patch] KVM: SVM: prevent DBG_DECRYPT and DBG_ENCRYPT overflow David Rientjes
@ 2019-03-28 13:58 ` Singh, Brijesh
  2019-04-04 20:55   ` David Rientjes
  2019-04-05 18:50 ` Paolo Bonzini
  1 sibling, 1 reply; 4+ messages in thread
From: Singh, Brijesh @ 2019-03-28 13:58 UTC (permalink / raw)
  To: David Rientjes, Joerg Roedel, Paolo Bonzini, Radim Krčmář
  Cc: Singh, Brijesh, Borislav Petkov, x86, kvm, linux-kernel



On 3/25/19 1:47 PM, David Rientjes wrote:
> This ensures that the address and length provided to DBG_DECRYPT and
> DBG_ENCRYPT do not cause an overflow.
> 
> At the same time, pass the actual number of pages pinned in memory to
> sev_unpin_memory() as a cleanup.
> 
> Reported-by: Cfir Cohen <cfir@google.com>
> Signed-off-by: David Rientjes <rientjes@google.com>
> ---
>   arch/x86/kvm/svm.c | 12 +++++++++---
>   1 file changed, 9 insertions(+), 3 deletions(-)
> 


Reviewed-by: Brijesh Singh <brijesh.singh@amd.com>

thanks

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

* Re: [patch] KVM: SVM: prevent DBG_DECRYPT and DBG_ENCRYPT overflow
  2019-03-28 13:58 ` Singh, Brijesh
@ 2019-04-04 20:55   ` David Rientjes
  0 siblings, 0 replies; 4+ messages in thread
From: David Rientjes @ 2019-04-04 20:55 UTC (permalink / raw)
  To: Singh, Brijesh
  Cc: Joerg Roedel, Paolo Bonzini, Radim Krčmář,
	Borislav Petkov, x86, kvm, linux-kernel

On Thu, 28 Mar 2019, Singh, Brijesh wrote:

> > This ensures that the address and length provided to DBG_DECRYPT and
> > DBG_ENCRYPT do not cause an overflow.
> > 
> > At the same time, pass the actual number of pages pinned in memory to
> > sev_unpin_memory() as a cleanup.
> > 
> > Reported-by: Cfir Cohen <cfir@google.com>
> > Signed-off-by: David Rientjes <rientjes@google.com>
> > ---
> >   arch/x86/kvm/svm.c | 12 +++++++++---
> >   1 file changed, 9 insertions(+), 3 deletions(-)
> > 
> 
> 
> Reviewed-by: Brijesh Singh <brijesh.singh@amd.com>
> 
> thanks
> 

Paolo, Radim, I don't see this in kvm.git, is it ready to be staged?

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

* Re: [patch] KVM: SVM: prevent DBG_DECRYPT and DBG_ENCRYPT overflow
  2019-03-25 18:47 [patch] KVM: SVM: prevent DBG_DECRYPT and DBG_ENCRYPT overflow David Rientjes
  2019-03-28 13:58 ` Singh, Brijesh
@ 2019-04-05 18:50 ` Paolo Bonzini
  1 sibling, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2019-04-05 18:50 UTC (permalink / raw)
  To: David Rientjes, Brijesh Singh, Joerg Roedel, Radim Krčmář
  Cc: Borislav Petkov, x86, kvm, linux-kernel

On 25/03/19 19:47, David Rientjes wrote:
> This ensures that the address and length provided to DBG_DECRYPT and
> DBG_ENCRYPT do not cause an overflow.
> 
> At the same time, pass the actual number of pages pinned in memory to
> sev_unpin_memory() as a cleanup.
> 
> Reported-by: Cfir Cohen <cfir@google.com>
> Signed-off-by: David Rientjes <rientjes@google.com>
> ---
>  arch/x86/kvm/svm.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -6799,7 +6799,8 @@ static int sev_dbg_crypt(struct kvm *kvm, struct kvm_sev_cmd *argp, bool dec)
>  	struct page **src_p, **dst_p;
>  	struct kvm_sev_dbg debug;
>  	unsigned long n;
> -	int ret, size;
> +	unsigned int size;
> +	int ret;
>  
>  	if (!sev_guest(kvm))
>  		return -ENOTTY;
> @@ -6807,6 +6808,11 @@ static int sev_dbg_crypt(struct kvm *kvm, struct kvm_sev_cmd *argp, bool dec)
>  	if (copy_from_user(&debug, (void __user *)(uintptr_t)argp->data, sizeof(debug)))
>  		return -EFAULT;
>  
> +	if (!debug.len || debug.src_uaddr + debug.len < debug.src_uaddr)
> +		return -EINVAL;
> +	if (!debug.dst_uaddr)
> +		return -EINVAL;
> +
>  	vaddr = debug.src_uaddr;
>  	size = debug.len;
>  	vaddr_end = vaddr + size;
> @@ -6857,8 +6863,8 @@ static int sev_dbg_crypt(struct kvm *kvm, struct kvm_sev_cmd *argp, bool dec)
>  						     dst_vaddr,
>  						     len, &argp->error);
>  
> -		sev_unpin_memory(kvm, src_p, 1);
> -		sev_unpin_memory(kvm, dst_p, 1);
> +		sev_unpin_memory(kvm, src_p, n);
> +		sev_unpin_memory(kvm, dst_p, n);
>  
>  		if (ret)
>  			goto err;
> 

Queued, thanks.

Paolo

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

end of thread, other threads:[~2019-04-05 18:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-25 18:47 [patch] KVM: SVM: prevent DBG_DECRYPT and DBG_ENCRYPT overflow David Rientjes
2019-03-28 13:58 ` Singh, Brijesh
2019-04-04 20:55   ` David Rientjes
2019-04-05 18:50 ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.