linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: 9p: Fix possible null-pointer dereference in p9_cm_event_handler()
@ 2021-08-10 13:20 Tuo Li
  2021-08-10 13:55 ` Leon Romanovsky
  0 siblings, 1 reply; 3+ messages in thread
From: Tuo Li @ 2021-08-10 13:20 UTC (permalink / raw)
  To: ericvh, lucho, asmadeus, davem, kuba
  Cc: v9fs-developer, netdev, linux-kernel, baijiaju1990, Tuo Li, TOTE Robot

The variable rdma is checked when event->event is equal to 
RDMA_CM_EVENT_DISCONNECTED:
  if (rdma)

This indicates that it can be NULL. If so, a null-pointer dereference will 
occur when calling complete():
  complete(&rdma->cm_done);

To fix this possible null-pointer dereference, calling complete() only 
when rdma is not NULL.

Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Tuo Li <islituo@gmail.com>
---
 net/9p/trans_rdma.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/9p/trans_rdma.c b/net/9p/trans_rdma.c
index af0a8a6cd3fd..fb3435dfd071 100644
--- a/net/9p/trans_rdma.c
+++ b/net/9p/trans_rdma.c
@@ -285,7 +285,8 @@ p9_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event)
 	default:
 		BUG();
 	}
-	complete(&rdma->cm_done);
+	if (rdma)
+		complete(&rdma->cm_done);
 	return 0;
 }
 
-- 
2.25.1


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

* Re: [PATCH] net: 9p: Fix possible null-pointer dereference in p9_cm_event_handler()
  2021-08-10 13:20 [PATCH] net: 9p: Fix possible null-pointer dereference in p9_cm_event_handler() Tuo Li
@ 2021-08-10 13:55 ` Leon Romanovsky
  2021-08-10 14:20   ` asmadeus
  0 siblings, 1 reply; 3+ messages in thread
From: Leon Romanovsky @ 2021-08-10 13:55 UTC (permalink / raw)
  To: Tuo Li
  Cc: ericvh, lucho, asmadeus, davem, kuba, v9fs-developer, netdev,
	linux-kernel, baijiaju1990, TOTE Robot

On Tue, Aug 10, 2021 at 06:20:07AM -0700, Tuo Li wrote:
> The variable rdma is checked when event->event is equal to 
> RDMA_CM_EVENT_DISCONNECTED:
>   if (rdma)
> 
> This indicates that it can be NULL. If so, a null-pointer dereference will 
> occur when calling complete():
>   complete(&rdma->cm_done);
> 
> To fix this possible null-pointer dereference, calling complete() only 
> when rdma is not NULL.

You need to explain how is it possible and blindly set if () checks.
I would say first "if (rdma)" is not needed, but don't know for sure.

> 
> Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
> Signed-off-by: Tuo Li <islituo@gmail.com>
> ---
>  net/9p/trans_rdma.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/net/9p/trans_rdma.c b/net/9p/trans_rdma.c
> index af0a8a6cd3fd..fb3435dfd071 100644
> --- a/net/9p/trans_rdma.c
> +++ b/net/9p/trans_rdma.c
> @@ -285,7 +285,8 @@ p9_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event)
>  	default:
>  		BUG();
>  	}
> -	complete(&rdma->cm_done);
> +	if (rdma)
> +		complete(&rdma->cm_done);
>  	return 0;
>  }
>  
> -- 
> 2.25.1
> 

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

* Re: [PATCH] net: 9p: Fix possible null-pointer dereference in p9_cm_event_handler()
  2021-08-10 13:55 ` Leon Romanovsky
@ 2021-08-10 14:20   ` asmadeus
  0 siblings, 0 replies; 3+ messages in thread
From: asmadeus @ 2021-08-10 14:20 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: Tuo Li, ericvh, lucho, davem, kuba, v9fs-developer, netdev,
	linux-kernel, baijiaju1990, TOTE Robot

Leon Romanovsky wrote on Tue, Aug 10, 2021 at 04:55:42PM +0300:
> On Tue, Aug 10, 2021 at 06:20:07AM -0700, Tuo Li wrote:
> > The variable rdma is checked when event->event is equal to 
> > RDMA_CM_EVENT_DISCONNECTED:
> >   if (rdma)
> > 
> > This indicates that it can be NULL. If so, a null-pointer dereference will 
> > occur when calling complete():
> >   complete(&rdma->cm_done);
> > 
> > To fix this possible null-pointer dereference, calling complete() only 
> > when rdma is not NULL.
> 
> You need to explain how is it possible and blindly set if () checks.
> I would say first "if (rdma)" is not needed, but don't know for sure.

Sounds like static analysis because there's a if (rdma) check in
RDMA_CM_EVENT_DISCONNECTED above, so if that needed check then it will
bug right afterwards

I'd tend to agree I don't think it's possible client->trans is null
there (it's filled right after rdma_create_id which defines the handler,
there might be a window where the callback is called before? But as I
understand it shouldn't be called until we resolve address and connect
then later disconnect)

So, I agree with Leon - unless you have a backtrace of a real bug
let's remove the other 'if' if you want to cleanup something for your
robot.

-- 
Dominique

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

end of thread, other threads:[~2021-08-10 14:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-10 13:20 [PATCH] net: 9p: Fix possible null-pointer dereference in p9_cm_event_handler() Tuo Li
2021-08-10 13:55 ` Leon Romanovsky
2021-08-10 14:20   ` asmadeus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).