Skip to contentSkip to conversation

mips/kvm: fix ioctl error handling

PATCH In review Michael S. Tsirkin 3 participants 3 messages Feb 28, 2016 – Mar 2, 2016

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

PATCH 1/1 mips/kvm: fix ioctl error handling

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.

---

Untested.

 arch/mips/kvm/mips.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/mips/kvm/mips.c +2 -2
index 8bc3977..3110447 100644
@@ -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;
 	}
Signature · 1 line
MST
#1 lore raw

Hello.

Quoted 1 line · Michael S. Tsirkin

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

Calling return? Perhaps "returning the result of"?

Quoted 5 lines

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

Quoted 8 lines
	return copy_to_user(...)) ?  -EFAULT : 0;
and
	return copy_from_user(...)) ?  -EFAULT : 0;

everywhere.

[...]

MBR, Sergei

maintainer
#2 lore raw
In reply to Michael S. Tsirkin
Quoted 36 lines · Michael S. Tsirkin

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.

---

Untested.

 arch/mips/kvm/mips.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/mips/kvm/mips.c +1 -1
index 8bc3977..3110447 100644
@@ -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;
 	}

arch/mips/kvm/mips.c static int kvm_mips_set_reg(struct kvm_vcpu *vcpu, · line 738

Quoted 8 lines
arch/mips/kvm/mips.c +1 -1
@@ -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