mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] RDMA/core: Fix member use-after-free in process_group_error()
@ 2026-09-16 18:45 Wentao Liang
  2026-09-23  8:47 ` Leon Romanovsky
  0 siblings, 1 reply; 2+ messages in thread
From: Wentao Liang @ 2026-09-16 18:45 UTC (permalink / raw)
  To: jgg; +Cc: leon, linux-kernel, linux-rdma, rolandd, Wentao Liang, stable

If the callback on the error path returns non-zero after a concurrent
ib_sa_free_multicast() already dropped the initial member reference,
dropping our temporary reference completes the waiter, which then frees
the member before ib_sa_free_multicast() dereferences it again.

Only free the multicast member when our reference decrement was not
the last one; otherwise the concurrent free is already in flight.

Fixes: faec2f7b96b5 ("IB/sa: Track multicast join/leave requests")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/infiniband/core/multicast.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/core/multicast.c b/drivers/infiniband/core/multicast.c
index bea7df3dd8f3..aa6fdac5fcde 100644
--- a/drivers/infiniband/core/multicast.c
+++ b/drivers/infiniband/core/multicast.c
@@ -409,8 +409,9 @@ static void process_group_error(struct mcast_group *group)
 
 		ret = member->multicast.callback(-ENETRESET,
 						 &member->multicast);
-		deref_member(member);
-		if (ret)
+		if (refcount_dec_and_test(&member->refcount))
+			complete(&member->comp);
+		else if (ret)
 			ib_sa_free_multicast(&member->multicast);
 		spin_lock_irq(&group->lock);
 	}
-- 
2.34.1


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

* Re: [PATCH] RDMA/core: Fix member use-after-free in process_group_error()
  2026-09-16 18:45 [PATCH] RDMA/core: Fix member use-after-free in process_group_error() Wentao Liang
@ 2026-09-23  8:47 ` Leon Romanovsky
  0 siblings, 0 replies; 2+ messages in thread
From: Leon Romanovsky @ 2026-09-23  8:47 UTC (permalink / raw)
  To: Wentao Liang; +Cc: jgg, linux-kernel, linux-rdma, rolandd, stable

On Wed, Sep 16, 2026 at 06:45:55PM +0000, Wentao Liang wrote:
> If the callback on the error path returns non-zero after a concurrent
> ib_sa_free_multicast() already dropped the initial member reference,
> dropping our temporary reference completes the waiter, which then frees
> the member before ib_sa_free_multicast() dereferences it again.
> 
> Only free the multicast member when our reference decrement was not
> the last one; otherwise the concurrent free is already in flight.

I'm not sure that last sentence is correct. Can you prove it?
Because we have the following code:
  662 void ib_sa_free_multicast(struct ib_sa_multicast *multicast)
  663 {
  ...
  685
  686         deref_member(member);
  687         wait_for_completion(&member->comp);
  ...
  691 EXPORT_SYMBOL(ib_sa_free_multicast);

Thanks

> 
> Fixes: faec2f7b96b5 ("IB/sa: Track multicast join/leave requests")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>  drivers/infiniband/core/multicast.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/infiniband/core/multicast.c b/drivers/infiniband/core/multicast.c
> index bea7df3dd8f3..aa6fdac5fcde 100644
> --- a/drivers/infiniband/core/multicast.c
> +++ b/drivers/infiniband/core/multicast.c
> @@ -409,8 +409,9 @@ static void process_group_error(struct mcast_group *group)
>  
>  		ret = member->multicast.callback(-ENETRESET,
>  						 &member->multicast);
> -		deref_member(member);
> -		if (ret)
> +		if (refcount_dec_and_test(&member->refcount))
> +			complete(&member->comp);
> +		else if (ret)
>  			ib_sa_free_multicast(&member->multicast);
>  		spin_lock_irq(&group->lock);
>  	}
> -- 
> 2.34.1
> 

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

end of thread, other threads:[~2026-09-23  8:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-16 18:45 [PATCH] RDMA/core: Fix member use-after-free in process_group_error() Wentao Liang
2026-09-23  8:47 ` Leon Romanovsky

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®