Skip to content

Commit

Permalink
KVM: arm64/sve: WARN when avoiding divide-by-zero in sve_reg_to_region()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Dave Martin authored and Marc Zyngier committed Apr 18, 2019
1 parent 52110aa commit 55ffad3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion arch/arm64/kvm/guest.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ static int sve_reg_to_region(struct sve_state_reg_region *region,
}

sve_state_size = vcpu_sve_state_size(vcpu);
if (!sve_state_size)
if (WARN_ON(!sve_state_size))
return -EINVAL;

region->koffset = array_index_nospec(reqoffset, sve_state_size);
Expand Down

0 comments on commit 55ffad3

Please sign in to comment.