[PATCH v2] VMCI: Fix NULL pointer dereference on context ptr

From: Xiyu Yang
Date: Mon Mar 23 2020 - 04:28:30 EST


A NULL vmci_ctx object may pass to vmci_ctx_put() from its callers.
Add a NULL check to prevent NULL pointer dereference.

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

diff --git a/drivers/misc/vmw_vmci/vmci_context.c b/drivers/misc/vmw_vmci/vmci_context.c
index 16695366ec92..2f4963ab51bd 100644
--- a/drivers/misc/vmw_vmci/vmci_context.c
+++ b/drivers/misc/vmw_vmci/vmci_context.c
@@ -494,7 +494,8 @@ static void ctx_free_ctx(struct kref *kref)
*/
void vmci_ctx_put(struct vmci_ctx *context)
{
- kref_put(&context->kref, ctx_free_ctx);
+ if (context)
+ kref_put(&context->kref, ctx_free_ctx);
}

/*
--
2.7.4