Skip to content

Commit d57a213

Browse files
lifeixacrnsi-robot
authored andcommitted
hv: hypercall: hot fix call assign/deassign mmiodev could crash hv
If we assign the mmio device address and size maliciously, this may crash the HV, SOS even the UOS. This patch is a hot fix. The formal one needs the config tool to configure the mmio device which we could pass through and the HV check the mmio device by it. Tracked-On: #5555 Signed-off-by: Li Fei1 <[email protected]>
1 parent ee07a43 commit d57a213

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

hypervisor/common/hypercall.c

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,25 @@ int32_t hcall_deassign_pcidev(struct acrn_vm *vm, struct acrn_vm *target_vm, __u
847847
return ret;
848848
}
849849

850+
static bool is_mmiodev_valid(struct acrn_mmiodev *mmiodev)
851+
{
852+
bool ret = true;
853+
854+
/* TODO: we should define the mmiodev which we could pt in the vmconfig,
855+
* then check the mmiodev whether the address and size are valid
856+
* according the vmconfig. Now we only could pt the TPM acpi device.
857+
*/
858+
if ((mmiodev->base_gpa != 0xFED40000UL) ||
859+
(mmiodev->base_hpa != 0xFED40000UL) ||
860+
(mmiodev->size != 0x00005000UL)) {
861+
ret = false;
862+
pr_fatal("%s, invalid mmiodev gpa: 0x%lx, hpa: 0x%lx, size: 0x%lx",
863+
__func__, mmiodev->base_gpa, mmiodev->base_hpa, mmiodev->size);
864+
}
865+
866+
return ret;
867+
}
868+
850869
/**
851870
* @brief Assign one MMIO dev to a VM.
852871
*
@@ -866,9 +885,11 @@ int32_t hcall_assign_mmiodev(struct acrn_vm *vm, struct acrn_vm *target_vm, __un
866885
/* We should only assign a device to a post-launched VM at creating time for safety, not runtime or other cases*/
867886
if (is_created_vm(target_vm)) {
868887
if (copy_from_gpa(vm, &mmiodev, param2, sizeof(mmiodev)) == 0) {
869-
ret = deassign_mmio_dev(vm, &mmiodev);
870-
if (ret == 0) {
871-
ret = assign_mmio_dev(target_vm, &mmiodev);
888+
if (is_mmiodev_valid(&mmiodev)) {
889+
ret = deassign_mmio_dev(vm, &mmiodev);
890+
if (ret == 0) {
891+
ret = assign_mmio_dev(target_vm, &mmiodev);
892+
}
872893
}
873894
}
874895
} else {
@@ -897,9 +918,11 @@ int32_t hcall_deassign_mmiodev(struct acrn_vm *vm, struct acrn_vm *target_vm, __
897918
/* We should only de-assign a device from a post-launched VM at creating/shutdown/reset time */
898919
if ((is_paused_vm(target_vm) || is_created_vm(target_vm))) {
899920
if (copy_from_gpa(vm, &mmiodev, param2, sizeof(mmiodev)) == 0) {
900-
ret = deassign_mmio_dev(target_vm, &mmiodev);
901-
if (ret == 0) {
902-
ret = assign_mmio_dev(vm, &mmiodev);
921+
if (is_mmiodev_valid(&mmiodev)) {
922+
ret = deassign_mmio_dev(target_vm, &mmiodev);
923+
if (ret == 0) {
924+
ret = assign_mmio_dev(vm, &mmiodev);
925+
}
903926
}
904927
}
905928
} else {

0 commit comments

Comments
 (0)