Skip to contentSkip to conversation

arm/kvm: fix ioctl error handling

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

Subsystems (5)
Stable branch Arm (32-bit) KVM arm64 +1 more subsystems
lore
Share & tools
lore
#0 lore raw

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

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

Fix up kvm to do

	return copy_to_user(...)) ?  -EFAULT : 0;

everywhere.

---

Compiled only.

 arch/arm/kvm/guest.c   | 2 +-
 arch/arm64/kvm/guest.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm/kvm/guest.c +1 -1
index 5fa69d7..99361f1 100644
@@ -161,7 +161,7 @@ static int get_timer_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 	u64 val;
 
 	val = kvm_arm_timer_get_reg(vcpu, reg->id);
-	return copy_to_user(uaddr, &val, KVM_REG_SIZE(reg->id));
+	return copy_to_user(uaddr, &val, KVM_REG_SIZE(reg->id)) ? -EFAULT : 0;
 }
 
 static unsigned long num_core_regs(void)
arch/arm64/kvm/guest.c +1 -1
index fcb7788..9e54ad7 100644
@@ -194,7 +194,7 @@ static int get_timer_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 	u64 val;
 
 	val = kvm_arm_timer_get_reg(vcpu, reg->id);
-	return copy_to_user(uaddr, &val, KVM_REG_SIZE(reg->id));
+	return copy_to_user(uaddr, &val, KVM_REG_SIZE(reg->id)) ? -EFAULT : 0;
 }
 
 /**
Signature · 1 line
MST