hv: fix potential NULL pointer reference in hc_assgin_ptdev

this patch validates input 'vdev->pdev' before
 reference to avoid potenial hypervisor crash.

[v2] update:
 Combine condition check for 'vdev' and 'vdev->pdev'

Tracked-On: #4334
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
Reviewed-by: Fei Li <fei1.li@intel.com>
This commit is contained in:
Yonghua Huang 2020-01-06 16:16:30 +08:00 committed by wenlingz
parent ddebefb9b4
commit 0e47f0a8f9
1 changed files with 1 additions and 1 deletions

View File

@ -836,7 +836,7 @@ int32_t hcall_assign_ptdev(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
spinlock_obtain(&vm->vpci.lock); spinlock_obtain(&vm->vpci.lock);
vdev = pci_find_vdev(&vm->vpci, bdf); vdev = pci_find_vdev(&vm->vpci, bdf);
if (vdev == NULL) { if ((vdev == NULL) || (vdev->pdev == NULL)) {
pr_fatal("%s %x:%x.%x not found\n", __func__, bdf.bits.b, bdf.bits.d, bdf.bits.f); pr_fatal("%s %x:%x.%x not found\n", __func__, bdf.bits.b, bdf.bits.d, bdf.bits.f);
ret = -EPERM; ret = -EPERM;
} else { } else {