Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH] RDMA/ucma: Fix use-after-free in ucma_create_uevent
@ 2026-05-03 10:51 shaikh.kamal
  2026-05-11 18:13 ` Leon Romanovsky
  0 siblings, 1 reply; 2+ messages in thread
From: shaikh.kamal @ 2026-05-03 10:51 UTC (permalink / raw)
  To: shaikh.kamal, Roland Dreier, linux-rdma, linux-kernel
  Cc: skhan, me, syzbot+a6ffe86390c8a6afc818

ucma_create_uevent() dereferences event->param.ud.private_data
as a struct ucma_multicast for multicast events. However,
this pointer may refer to memory that has already been freed,
leading to a use-after-free.

Fix this by avoiding dereferencing private_data for multicast
events and instead using ctx for uid and id, which has a
well-defined lifetime.

Tested by running the reproducer under KASAN with slub_debug
enabled for several hours with no crashes observed.

Reported-by: syzbot+a6ffe86390c8a6afc818@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=a6ffe86390c8a6afc818
Fixes: c8f6a362bf3e ("RDMA/cma: Add multicast communication support")

Signed-off-by: shaikh.kamal <shaikhkamal2012@gmail.com>
---
 drivers/infiniband/core/ucma.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
index 6e700b974033..8eef10352af7 100644
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -270,10 +270,12 @@ static struct ucma_event *ucma_create_uevent(struct ucma_context *ctx,
 	switch (event->event) {
 	case RDMA_CM_EVENT_MULTICAST_JOIN:
 	case RDMA_CM_EVENT_MULTICAST_ERROR:
-		uevent->mc = (struct ucma_multicast *)
-			     event->param.ud.private_data;
-		uevent->resp.uid = uevent->mc->uid;
-		uevent->resp.id = uevent->mc->id;
+		/*
+		 * event->param.ud.private_data may point to a ucma_multicast
+		 * that has already been freed, so use ctx instead.
+		 */
+		uevent->resp.uid = ctx->uid;
+		uevent->resp.id = ctx->id;
 		break;
 	default:
 		uevent->resp.uid = ctx->uid;
-- 
2.43.0


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

* Re: [PATCH] RDMA/ucma: Fix use-after-free in ucma_create_uevent
  2026-05-03 10:51 [PATCH] RDMA/ucma: Fix use-after-free in ucma_create_uevent shaikh.kamal
@ 2026-05-11 18:13 ` Leon Romanovsky
  0 siblings, 0 replies; 2+ messages in thread
From: Leon Romanovsky @ 2026-05-11 18:13 UTC (permalink / raw)
  To: shaikh.kamal
  Cc: Roland Dreier, linux-rdma, linux-kernel, skhan, me,
	syzbot+a6ffe86390c8a6afc818

On Sun, May 03, 2026 at 04:21:25PM +0530, shaikh.kamal wrote:
> ucma_create_uevent() dereferences event->param.ud.private_data
> as a struct ucma_multicast for multicast events. However,
> this pointer may refer to memory that has already been freed,
> leading to a use-after-free.
> 
> Fix this by avoiding dereferencing private_data for multicast
> events and instead using ctx for uid and id, which has a
> well-defined lifetime.
> 
> Tested by running the reproducer under KASAN with slub_debug
> enabled for several hours with no crashes observed.
> 
> Reported-by: syzbot+a6ffe86390c8a6afc818@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=a6ffe86390c8a6afc818
> Fixes: c8f6a362bf3e ("RDMA/cma: Add multicast communication support")
> 
> Signed-off-by: shaikh.kamal <shaikhkamal2012@gmail.com>
> ---
>  drivers/infiniband/core/ucma.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
> index 6e700b974033..8eef10352af7 100644
> --- a/drivers/infiniband/core/ucma.c
> +++ b/drivers/infiniband/core/ucma.c
> @@ -270,10 +270,12 @@ static struct ucma_event *ucma_create_uevent(struct ucma_context *ctx,
>  	switch (event->event) {
>  	case RDMA_CM_EVENT_MULTICAST_JOIN:
>  	case RDMA_CM_EVENT_MULTICAST_ERROR:
> -		uevent->mc = (struct ucma_multicast *)
> -			     event->param.ud.private_data;
> -		uevent->resp.uid = uevent->mc->uid;
> -		uevent->resp.id = uevent->mc->id;
> +		/*
> +		 * event->param.ud.private_data may point to a ucma_multicast
> +		 * that has already been freed, so use ctx instead.
> +		 */
> +		uevent->resp.uid = ctx->uid;
> +		uevent->resp.id = ctx->id;

I believe your analysis is correct, but the implementation is not.  
Are you certain that `ctx->uid == uevent->mc->uid` and `ctx->id == uevent->mc->id`?

Thanks

>  		break;
>  	default:
>  		uevent->resp.uid = ctx->uid;
> -- 
> 2.43.0
> 
> 

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

end of thread, other threads:[~2026-05-11 18:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-03 10:51 [PATCH] RDMA/ucma: Fix use-after-free in ucma_create_uevent shaikh.kamal
2026-05-11 18:13 ` Leon Romanovsky

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