KVM: arm64: Prevent userspace from handling SMC64 arch range
authorOliver Upton <oliver.upton@linux.dev>
Sat, 8 Apr 2023 12:17:31 +0000 (12:17 +0000)
committerMarc Zyngier <maz@kernel.org>
Sat, 8 Apr 2023 14:22:55 +0000 (15:22 +0100)
Though presently unused, there is an SMC64 view of the Arm architecture
calls defined by the SMCCC. The documentation of the SMCCC filter states
that the SMC64 range is reserved, but nothing actually prevents
userspace from applying a filter to the range.

Insert a range with the HANDLE action for the SMC64 arch range, thereby
preventing userspace from imposing filtering/forwarding on it.

Fixes: fb88707dd39b ("KVM: arm64: Use a maple tree to represent the SMCCC filter")
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20230408121732.3411329-2-oliver.upton@linux.dev
arch/arm64/kvm/hypercalls.c

index 3b6523f..47254a3 100644 (file)
@@ -121,11 +121,17 @@ static bool kvm_smccc_test_fw_bmap(struct kvm_vcpu *vcpu, u32 func_id)
        }
 }
 
-#define SMCCC_ARCH_RANGE_BEGIN ARM_SMCCC_VERSION_FUNC_ID
-#define SMCCC_ARCH_RANGE_END                           \
-       ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,         \
-                          ARM_SMCCC_SMC_32,            \
-                          0, ARM_SMCCC_FUNC_MASK)
+#define SMC32_ARCH_RANGE_BEGIN ARM_SMCCC_VERSION_FUNC_ID
+#define SMC32_ARCH_RANGE_END   ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,         \
+                                                  ARM_SMCCC_SMC_32,            \
+                                                  0, ARM_SMCCC_FUNC_MASK)
+
+#define SMC64_ARCH_RANGE_BEGIN ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,         \
+                                                  ARM_SMCCC_SMC_64,            \
+                                                  0, 0)
+#define SMC64_ARCH_RANGE_END   ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,         \
+                                                  ARM_SMCCC_SMC_64,            \
+                                                  0, ARM_SMCCC_FUNC_MASK)
 
 static void init_smccc_filter(struct kvm *kvm)
 {
@@ -139,10 +145,17 @@ static void init_smccc_filter(struct kvm *kvm)
         * to the guest.
         */
        r = mtree_insert_range(&kvm->arch.smccc_filter,
-                              SMCCC_ARCH_RANGE_BEGIN, SMCCC_ARCH_RANGE_END,
+                              SMC32_ARCH_RANGE_BEGIN, SMC32_ARCH_RANGE_END,
                               xa_mk_value(KVM_SMCCC_FILTER_HANDLE),
                               GFP_KERNEL_ACCOUNT);
        WARN_ON_ONCE(r);
+
+       r = mtree_insert_range(&kvm->arch.smccc_filter,
+                              SMC64_ARCH_RANGE_BEGIN, SMC64_ARCH_RANGE_END,
+                              xa_mk_value(KVM_SMCCC_FILTER_HANDLE),
+                              GFP_KERNEL_ACCOUNT);
+       WARN_ON_ONCE(r);
+
 }
 
 static int kvm_smccc_set_filter(struct kvm *kvm, struct kvm_smccc_filter __user *uaddr)