Re: [PATCH v4 02/17] arm: KVM: Fix SMCCC handling of unimplemented SMC/HVC calls

From: Christoffer Dall
Date: Wed Feb 07 2018 - 03:33:00 EST


On Tue, Feb 06, 2018 at 05:56:06PM +0000, Marc Zyngier wrote:
> KVM doesn't follow the SMCCC when it comes to unimplemented calls,
> and inject an UNDEF instead of returning an error. Since firmware
> calls are now used for security mitigation, they are becoming more
> common, and the undef is counter productive.
>
> Instead, let's follow the SMCCC which states that -1 must be returned
> to the caller when getting an unknown function number.

Apparently I forgot to review this:

Reviewed-by: Christoffer Dall <christoffer.dall@xxxxxxxxxx>

>
> Cc: <stable@xxxxxxxxxxxxxxx>
> Tested-by: Ard Biesheuvel <ard.biesheuvel@xxxxxxxxxx>
> Signed-off-by: Marc Zyngier <marc.zyngier@xxxxxxx>
> ---
> arch/arm/kvm/handle_exit.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm/kvm/handle_exit.c b/arch/arm/kvm/handle_exit.c
> index cf8bf6bf87c4..a4bf0f6f024a 100644
> --- a/arch/arm/kvm/handle_exit.c
> +++ b/arch/arm/kvm/handle_exit.c
> @@ -38,7 +38,7 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run)
>
> ret = kvm_psci_call(vcpu);
> if (ret < 0) {
> - kvm_inject_undefined(vcpu);
> + vcpu_set_reg(vcpu, 0, ~0UL);
> return 1;
> }
>
> @@ -47,7 +47,16 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run)
>
> static int handle_smc(struct kvm_vcpu *vcpu, struct kvm_run *run)
> {
> - kvm_inject_undefined(vcpu);
> + /*
> + * "If an SMC instruction executed at Non-secure EL1 is
> + * trapped to EL2 because HCR_EL2.TSC is 1, the exception is a
> + * Trap exception, not a Secure Monitor Call exception [...]"
> + *
> + * We need to advance the PC after the trap, as it would
> + * otherwise return to the same address...
> + */
> + vcpu_set_reg(vcpu, 0, ~0UL);
> + kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu));
> return 1;
> }
>
> --
> 2.14.2
>