Skip to contentSkip to conversation

LoongArch: KVM: Check return values for put_user

PATCH In review Qiang Ma 2 participants 2 messages May 26 – May 27

Subsystems (3)
lore
Share & tools
lore

Qiang Ma

author
#0 lore raw

PATCH 1/1 LoongArch: KVM: Check return values for put_user

put_user() may return -EFAULT, so, when the user space address is invalid, it should return -EFAULT.

---
 arch/loongarch/kvm/vcpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/loongarch/kvm/vcpu.c +2 -1
index 782dc1a36e29..67441edf0e1f 100644
@@ -1104,7 +1104,8 @@ static int kvm_loongarch_cpucfg_get_attr(struct kvm_vcpu *vcpu,
 		return -ENXIO;
 	}
 
-	put_user(val, uaddr);
+	if (put_user(val, uaddr))
+		return -EFAULT;
 
 	return ret;
 }
Signature · 1 line
2.20.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Qiang Ma

put_user() may return -EFAULT, so, when the user space address is invalid, it should return -EFAULT.

---
  arch/loongarch/kvm/vcpu.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/loongarch/kvm/vcpu.c +0 -0
index 782dc1a36e29..67441edf0e1f 100644

arch/loongarch/kvm/vcpu.c static int kvm_loongarch_cpucfg_get_attr(struct kvm_vcpu *vcpu, · line 1111

Quoted 9 lines
arch/loongarch/kvm/vcpu.c +2 -1
@@ -1104,7 +1104,8 @@ static int kvm_loongarch_cpucfg_get_attr(struct kvm_vcpu *vcpu,
  		return -ENXIO;
  	}
 
-	put_user(val, uaddr);
+	if (put_user(val, uaddr))
+		return -EFAULT;
 
  	return ret;
  }