From 0e47f0a8f9d306b58ba744c266f64e8e84186b4f Mon Sep 17 00:00:00 2001 From: Yonghua Huang Date: Mon, 6 Jan 2020 16:16:30 +0800 Subject: [PATCH] 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 Reviewed-by: Fei Li --- hypervisor/common/hypercall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index 6a0d07aaa..dc10689f9 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -836,7 +836,7 @@ int32_t hcall_assign_ptdev(struct acrn_vm *vm, uint16_t vmid, uint64_t param) spinlock_obtain(&vm->vpci.lock); 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); ret = -EPERM; } else {