Skip to content

Commit 5a23ad6

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: Prevent userspace from handling SMC64 arch range
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: fb88707 ("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
1 parent 0e5c9a9 commit 5a23ad6

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

arch/arm64/kvm/hypercalls.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,17 @@ static bool kvm_smccc_test_fw_bmap(struct kvm_vcpu *vcpu, u32 func_id)
121121
}
122122
}
123123

124-
#define SMCCC_ARCH_RANGE_BEGIN ARM_SMCCC_VERSION_FUNC_ID
125-
#define SMCCC_ARCH_RANGE_END \
126-
ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \
127-
ARM_SMCCC_SMC_32, \
128-
0, ARM_SMCCC_FUNC_MASK)
124+
#define SMC32_ARCH_RANGE_BEGIN ARM_SMCCC_VERSION_FUNC_ID
125+
#define SMC32_ARCH_RANGE_END ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \
126+
ARM_SMCCC_SMC_32, \
127+
0, ARM_SMCCC_FUNC_MASK)
128+
129+
#define SMC64_ARCH_RANGE_BEGIN ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \
130+
ARM_SMCCC_SMC_64, \
131+
0, 0)
132+
#define SMC64_ARCH_RANGE_END ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \
133+
ARM_SMCCC_SMC_64, \
134+
0, ARM_SMCCC_FUNC_MASK)
129135

130136
static void init_smccc_filter(struct kvm *kvm)
131137
{
@@ -139,10 +145,17 @@ static void init_smccc_filter(struct kvm *kvm)
139145
* to the guest.
140146
*/
141147
r = mtree_insert_range(&kvm->arch.smccc_filter,
142-
SMCCC_ARCH_RANGE_BEGIN, SMCCC_ARCH_RANGE_END,
148+
SMC32_ARCH_RANGE_BEGIN, SMC32_ARCH_RANGE_END,
143149
xa_mk_value(KVM_SMCCC_FILTER_HANDLE),
144150
GFP_KERNEL_ACCOUNT);
145151
WARN_ON_ONCE(r);
152+
153+
r = mtree_insert_range(&kvm->arch.smccc_filter,
154+
SMC64_ARCH_RANGE_BEGIN, SMC64_ARCH_RANGE_END,
155+
xa_mk_value(KVM_SMCCC_FILTER_HANDLE),
156+
GFP_KERNEL_ACCOUNT);
157+
WARN_ON_ONCE(r);
158+
146159
}
147160

148161
static int kvm_smccc_set_filter(struct kvm *kvm, struct kvm_smccc_filter __user *uaddr)

0 commit comments

Comments
 (0)