Skip to contentSkip to conversation

KVM: arm64: Fix the descriptor address in __kvm_at_swap_desc()

PATCH Applied Zenghui Yu 2 participants 3 messages Mar 17

Subsystems (2)
lore
Share & tools
lore

Zenghui Yu

author
#0 lore raw

PATCH 1/1 KVM: arm64: Fix the descriptor address in __kvm_at_swap_desc()

From: "Zenghui Yu (Huawei)" <[email protected]>

Using "(u64 __user *)hva + offset" to get the virtual addresses of S1/S2 descriptors looks really wrong, if offset is not zero. What we want to get for swapping is hva + offset, not hva + offset*8. ;-)

Fix it.

Fixes f6927b41d573 ("KVM: arm64: Add helper for swapping guest descriptor")
---
 arch/arm64/kvm/at.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/at.c +1 -1
index c5c5644b1878..a024d9a770dc 100644
@@ -1753,7 +1753,7 @@ int __kvm_at_swap_desc(struct kvm *kvm, gpa_t ipa, u64 old, u64 new)
 	if (!writable)
 		return -EPERM;
 
-	ptep = (u64 __user *)hva + offset;
+	ptep = (void __user *)hva + offset;
 	if (cpus_have_final_cap(ARM64_HAS_LSE_ATOMICS))
 		r = __lse_swap_desc(ptep, old, new);
 	else
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 20 lines · Zenghui Yu

From: "Zenghui Yu (Huawei)" <[email protected]>

Using "(u64 __user *)hva + offset" to get the virtual addresses of S1/S2 descriptors looks really wrong, if offset is not zero. What we want to get for swapping is hva + offset, not hva + offset*8. ;-)

Fix it.

Fixes f6927b41d573 ("KVM: arm64: Add helper for swapping guest descriptor")
---
 arch/arm64/kvm/at.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/at.c +0 -0
index c5c5644b1878..a024d9a770dc 100644

arch/arm64/kvm/at.c int __kvm_at_swap_desc(struct kvm *kvm, gpa_t ipa, u64 old, u64 new) · line 1759

Quoted 8 lines
arch/arm64/kvm/at.c +1 -1
@@ -1753,7 +1753,7 @@ int __kvm_at_swap_desc(struct kvm *kvm, gpa_t ipa, u64 old, u64 new)
 	if (!writable)
 		return -EPERM;
 
-	ptep = (u64 __user *)hva + offset;
+	ptep = (void __user *)hva + offset;
 	if (cpus_have_final_cap(ARM64_HAS_LSE_ATOMICS))
 		r = __lse_swap_desc(ptep, old, new);
 	else

Holy crap! How did we miss that???

Thanks a lot for spotting it, I'll queue that now.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
maintainer Applied
#2 lore raw
In reply to Zenghui Yu
Quoted 8 lines · Zenghui Yu

Using "(u64 __user *)hva + offset" to get the virtual addresses of S1/S2 descriptors looks really wrong, if offset is not zero. What we want to get for swapping is hva + offset, not hva + offset*8. ;-)

Fix it.

[...]

Applied to fixes, thanks!

[1/1] KVM: arm64: Fix the descriptor address in __kvm_at_swap_desc()

      commit: 0496acc42fb51eee040b5170cec05cec41385540

Cheers,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.