Skip to content

Commit 66b7e05

Browse files
Steven PriceMarc Zyngier
authored andcommitted
KVM: arm64: Fix kvm_reset_vcpu() return code being incorrect with SVE
If SVE is enabled then 'ret' can be assigned the return value of kvm_vcpu_enable_sve() which may be 0 causing future "goto out" sites to erroneously return 0 on failure rather than -EINVAL as expected. Remove the initialisation of 'ret' and make setting the return value explicit to avoid this situation in the future. Fixes: 9a3cdf2 ("KVM: arm64/sve: Allow userspace to enable SVE for vcpus") Cc: [email protected] Reported-by: James Morse <[email protected]> Signed-off-by: Steven Price <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7733306 commit 66b7e05

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

arch/arm64/kvm/reset.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ static int kvm_vcpu_enable_ptrauth(struct kvm_vcpu *vcpu)
245245
*/
246246
int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
247247
{
248-
int ret = -EINVAL;
248+
int ret;
249249
bool loaded;
250250
u32 pstate;
251251

@@ -269,15 +269,19 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
269269

270270
if (test_bit(KVM_ARM_VCPU_PTRAUTH_ADDRESS, vcpu->arch.features) ||
271271
test_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, vcpu->arch.features)) {
272-
if (kvm_vcpu_enable_ptrauth(vcpu))
272+
if (kvm_vcpu_enable_ptrauth(vcpu)) {
273+
ret = -EINVAL;
273274
goto out;
275+
}
274276
}
275277

276278
switch (vcpu->arch.target) {
277279
default:
278280
if (test_bit(KVM_ARM_VCPU_EL1_32BIT, vcpu->arch.features)) {
279-
if (!cpus_have_const_cap(ARM64_HAS_32BIT_EL1))
281+
if (!cpus_have_const_cap(ARM64_HAS_32BIT_EL1)) {
282+
ret = -EINVAL;
280283
goto out;
284+
}
281285
pstate = VCPU_RESET_PSTATE_SVC;
282286
} else {
283287
pstate = VCPU_RESET_PSTATE_EL1;

0 commit comments

Comments
 (0)