[PATCH] VMCI: Fix dereference before NULL-check of context ptr

From: Xiyu Yang
Date: Mon Mar 16 2020 - 12:16:43 EST


A NULL pointer can be returned by vmci_ctx_get(). Thus add a
corresponding check so that a NULL pointer dereference will
be avoided in vmci_ctx_put().

Signed-off-by: Xiyu Yang <xiyuyang19@xxxxxxxxxxxx>
Signed-off-by: Xin Tan <tanxin.ctf@xxxxxxxxx>
---
drivers/misc/vmw_vmci/vmci_queue_pair.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c
index 8531ae781195..032617101ebc 100644
--- a/drivers/misc/vmw_vmci/vmci_queue_pair.c
+++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c
@@ -1859,7 +1859,8 @@ static int qp_detatch_host_work(struct vmci_handle handle)

result = vmci_qp_broker_detach(handle, context);

- vmci_ctx_put(context);
+ if (context)
+ vmci_ctx_put(context);
return result;
}

--
2.7.4