]> git.baikalelectronics.ru Git - kernel.git/commit
KVM: arm64/sve: WARN when avoiding divide-by-zero in sve_reg_to_region()
authorDave Martin <Dave.Martin@arm.com>
Thu, 11 Apr 2019 15:37:38 +0000 (16:37 +0100)
committerMarc Zyngier <marc.zyngier@arm.com>
Thu, 18 Apr 2019 16:14:01 +0000 (17:14 +0100)
commit1c1ff7c087e7e6a9505d64d024a62b2b66e98e4d
treef0cf6afc486239d4b1d7608d6d529b2ebffc1083
parent8425b8bc19efbbf5255595049be13c8e3905dacd
KVM: arm64/sve: WARN when avoiding divide-by-zero in sve_reg_to_region()

sve_reg_to_region() currently passes the result of
vcpu_sve_state_size() to array_index_nospec(), effectively
leading to a divide / modulo operation.

Currently the code bails out and returns -EINVAL if
vcpu_sve_state_size() turns out to be zero, in order to avoid going
ahead and attempting to divide by zero.  This is reasonable, but it
should only happen if the kernel contains some other bug that
allowed this code to be reached without the vcpu having been
properly initialised.

To make it clear that this is a defence against bugs rather than
something that the user should be able to trigger, this patch marks
the check with WARN_ON().

Suggested-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
arch/arm64/kvm/guest.c