mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] VMCI: Fix potential NULL pointer dereference when acquire a lock
@ 2020-03-16 16:36 Xiyu Yang
  2020-03-18 11:01 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Xiyu Yang @ 2020-03-16 16:36 UTC (permalink / raw)
  To: Arnd Bergmann, Greg Kroah-Hartman, Xiyu Yang, Vishnu DASA,
	Xin Tan, Allison Randal, Thomas Gleixner, linux-kernel
  Cc: yuanxzhang, kjlu

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

Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
---
 drivers/misc/vmw_vmci/vmci_context.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/misc/vmw_vmci/vmci_context.c b/drivers/misc/vmw_vmci/vmci_context.c
index 16695366ec92..a20878fba374 100644
--- a/drivers/misc/vmw_vmci/vmci_context.c
+++ b/drivers/misc/vmw_vmci/vmci_context.c
@@ -898,6 +898,8 @@ void vmci_ctx_rcv_notifications_release(u32 context_id,
 					bool success)
 {
 	struct vmci_ctx *context = vmci_ctx_get(context_id);
+	if (context == NULL)
+		return;
 
 	spin_lock(&context->lock);
 	if (!success) {
-- 
2.7.4


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] VMCI: Fix potential NULL pointer dereference when acquire a lock
  2020-03-16 16:36 [PATCH] VMCI: Fix potential NULL pointer dereference when acquire a lock Xiyu Yang
@ 2020-03-18 11:01 ` Greg Kroah-Hartman
  0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2020-03-18 11:01 UTC (permalink / raw)
  To: Xiyu Yang
  Cc: Arnd Bergmann, Vishnu DASA, Xin Tan, Allison Randal,
	Thomas Gleixner, linux-kernel, yuanxzhang, kjlu

On Tue, Mar 17, 2020 at 12:36:47AM +0800, Xiyu Yang wrote:
> A NULL pointer can be returned by vmci_ctx_get(). Thus add a
> corresponding check so that a NULL pointer dereference will
> be avoided when acquire a lock in spin_lock.
> 
> Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
> Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
> ---
>  drivers/misc/vmw_vmci/vmci_context.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/misc/vmw_vmci/vmci_context.c b/drivers/misc/vmw_vmci/vmci_context.c
> index 16695366ec92..a20878fba374 100644
> --- a/drivers/misc/vmw_vmci/vmci_context.c
> +++ b/drivers/misc/vmw_vmci/vmci_context.c
> @@ -898,6 +898,8 @@ void vmci_ctx_rcv_notifications_release(u32 context_id,
>  					bool success)
>  {
>  	struct vmci_ctx *context = vmci_ctx_get(context_id);
> +	if (context == NULL)
> +		return;

But, if you look at the code, context_id is guaranteed to point to a
valid context, right?  Or can this somehow get dropped between the last
"get" and this one?

Anyway, the coding style is wrong here, always run checkpatch.pl on your
patches please.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-18 11:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-16 16:36 [PATCH] VMCI: Fix potential NULL pointer dereference when acquire a lock Xiyu Yang
2020-03-18 11:01 ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®