Re: [PATCH] LoongArch: KVM: Check return values for put_user

From: Bibo Mao

Date: Wed May 27 2026 - 02:20:46 EST




On 2026/5/26 下午3:42, Qiang Ma wrote:
put_user() may return -EFAULT, so, when the user space address
is invalid, it should return -EFAULT.

Signed-off-by: Qiang Ma <maqianga@xxxxxxxxxxxxx>
---
arch/loongarch/kvm/vcpu.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c
index 782dc1a36e29..67441edf0e1f 100644
--- a/arch/loongarch/kvm/vcpu.c
+++ b/arch/loongarch/kvm/vcpu.c
@@ -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;
}

Reviewed-by: Bibo Mao <maobibo@xxxxxxxxxxx>