lkml.org 
[lkml]   [2024]   [Feb]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH for-6.8 v2 2/4] KVM: LoongArch: Fix kvm_check_cpucfg incorrectly accepting bad CPUCFG IDs
Date
From: WANG Xuerui <git@xen0n.name>

The return value of _kvm_get_cpucfg is meant to be checked, but this
was not done, so bad CPUCFG IDs wrongly fall back to the default case
and 0 is returned.

Check the return value to fix the UAPI behavior.

While at it, also remove the redundant range check, because
_kvm_get_cpucfg already rejects all unrecognized input CPUCFG IDs.
It was also wrong and no-op, in the same way as the former identical
check in _kvm_get_cpucfg.

Fixes: db1ecca22edf ("LoongArch: KVM: Add LSX (128bit SIMD) support")
Signed-off-by: WANG Xuerui <git@xen0n.name>
---
arch/loongarch/kvm/vcpu.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c
index c4a592623da6..cc2332b056ba 100644
--- a/arch/loongarch/kvm/vcpu.c
+++ b/arch/loongarch/kvm/vcpu.c
@@ -328,12 +328,10 @@ static int _kvm_get_cpucfg(int id, u64 *v)
static int kvm_check_cpucfg(int id, u64 val)
{
u64 mask;
- int ret = 0;
-
- if (id < 0 && id >= KVM_MAX_CPUCFG_REGS)
- return -EINVAL;
+ int ret;

- if (_kvm_get_cpucfg(id, &mask))
+ ret = _kvm_get_cpucfg(id, &mask);
+ if (ret)
return ret;

switch (id) {
--
2.43.0

\
 
 \ /
  Last update: 2024-05-27 15:02    [W:0.070 / U:0.964 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site