stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH for-4,5] mips/kvm: fix ioctl error handling
@ 2016-02-28 15:35 Michael S. Tsirkin
  2016-02-28 17:35 ` Sergei Shtylyov
  2016-03-02  9:35 ` Paolo Bonzini
  0 siblings, 2 replies; 3+ messages in thread
From: Michael S. Tsirkin @ 2016-02-28 15:35 UTC (permalink / raw)
  To: linux-kernel
  Cc: stable, Paolo Bonzini, James Hogan, Ralf Baechle, kvm, linux-mips

Calling return copy_to_user(...) or return copy_from_user in an ioctl
will not do the right thing if there's a pagefault:
copy_to_user/copy_from_user return the number of bytes not copied in
this case.

Fix up kvm on mips to do
	return copy_to_user(...)) ?  -EFAULT : 0;
and
	return copy_from_user(...)) ?  -EFAULT : 0;

everywhere.

Cc: stable@vger.kernel.org
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---

Untested.

 arch/mips/kvm/mips.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
index 8bc3977..3110447 100644
--- a/arch/mips/kvm/mips.c
+++ b/arch/mips/kvm/mips.c
@@ -702,7 +702,7 @@ static int kvm_mips_get_reg(struct kvm_vcpu *vcpu,
 	} else if ((reg->id & KVM_REG_SIZE_MASK) == KVM_REG_SIZE_U128) {
 		void __user *uaddr = (void __user *)(long)reg->addr;
 
-		return copy_to_user(uaddr, vs, 16);
+		return copy_to_user(uaddr, vs, 16) ? -EFAULT : 0;
 	} else {
 		return -EINVAL;
 	}
@@ -732,7 +732,7 @@ static int kvm_mips_set_reg(struct kvm_vcpu *vcpu,
 	} else if ((reg->id & KVM_REG_SIZE_MASK) == KVM_REG_SIZE_U128) {
 		void __user *uaddr = (void __user *)(long)reg->addr;
 
-		return copy_from_user(vs, uaddr, 16);
+		return copy_from_user(vs, uaddr, 16) ? -EFAULT : 0;
 	} else {
 		return -EINVAL;
 	}
-- 
MST

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

* Re: [PATCH for-4,5] mips/kvm: fix ioctl error handling
  2016-02-28 15:35 [PATCH for-4,5] mips/kvm: fix ioctl error handling Michael S. Tsirkin
@ 2016-02-28 17:35 ` Sergei Shtylyov
  2016-03-02  9:35 ` Paolo Bonzini
  1 sibling, 0 replies; 3+ messages in thread
From: Sergei Shtylyov @ 2016-02-28 17:35 UTC (permalink / raw)
  To: Michael S. Tsirkin, linux-kernel
  Cc: stable, Paolo Bonzini, James Hogan, Ralf Baechle, kvm, linux-mips

Hello.

On 02/28/2016 06:35 PM, Michael S. Tsirkin wrote:

> Calling return copy_to_user(...) or return copy_from_user in an ioctl

    Calling return? Perhaps "returning the result of"?

> will not do the right thing if there's a pagefault:
> copy_to_user/copy_from_user return the number of bytes not copied in
> this case.
>
> Fix up kvm on mips to do
> 	return copy_to_user(...)) ?  -EFAULT : 0;
> and
> 	return copy_from_user(...)) ?  -EFAULT : 0;
>
> everywhere.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
[...]

MBR, Sergei


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

* Re: [PATCH for-4,5] mips/kvm: fix ioctl error handling
  2016-02-28 15:35 [PATCH for-4,5] mips/kvm: fix ioctl error handling Michael S. Tsirkin
  2016-02-28 17:35 ` Sergei Shtylyov
@ 2016-03-02  9:35 ` Paolo Bonzini
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2016-03-02  9:35 UTC (permalink / raw)
  To: Michael S. Tsirkin, linux-kernel
  Cc: stable, James Hogan, Ralf Baechle, kvm, linux-mips



On 28/02/2016 16:35, Michael S. Tsirkin wrote:
> Calling return copy_to_user(...) or return copy_from_user in an ioctl
> will not do the right thing if there's a pagefault:
> copy_to_user/copy_from_user return the number of bytes not copied in
> this case.
> 
> Fix up kvm on mips to do
> 	return copy_to_user(...)) ?  -EFAULT : 0;
> and
> 	return copy_from_user(...)) ?  -EFAULT : 0;
> 
> everywhere.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> 
> Untested.
> 
>  arch/mips/kvm/mips.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
> index 8bc3977..3110447 100644
> --- a/arch/mips/kvm/mips.c
> +++ b/arch/mips/kvm/mips.c
> @@ -702,7 +702,7 @@ static int kvm_mips_get_reg(struct kvm_vcpu *vcpu,
>  	} else if ((reg->id & KVM_REG_SIZE_MASK) == KVM_REG_SIZE_U128) {
>  		void __user *uaddr = (void __user *)(long)reg->addr;
>  
> -		return copy_to_user(uaddr, vs, 16);
> +		return copy_to_user(uaddr, vs, 16) ? -EFAULT : 0;
>  	} else {
>  		return -EINVAL;
>  	}
> @@ -732,7 +732,7 @@ static int kvm_mips_set_reg(struct kvm_vcpu *vcpu,
>  	} else if ((reg->id & KVM_REG_SIZE_MASK) == KVM_REG_SIZE_U128) {
>  		void __user *uaddr = (void __user *)(long)reg->addr;
>  
> -		return copy_from_user(vs, uaddr, 16);
> +		return copy_from_user(vs, uaddr, 16) ? -EFAULT : 0;
>  	} else {
>  		return -EINVAL;
>  	}
> 

Applied with the commit message tweak suggested by Sergei.

Paolo

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

end of thread, other threads:[~2016-03-02  9:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-28 15:35 [PATCH for-4,5] mips/kvm: fix ioctl error handling Michael S. Tsirkin
2016-02-28 17:35 ` Sergei Shtylyov
2016-03-02  9:35 ` 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).