linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH jgg-for-next] RDMA/rxe: Fix pd refcount_t: underflow; use-after-free
@ 2022-09-27  5:25 Li Zhijian
  2022-09-27 13:14 ` Jason Gunthorpe
  0 siblings, 1 reply; 2+ messages in thread
From: Li Zhijian @ 2022-09-27  5:25 UTC (permalink / raw)
  To: zyjzyj2000, jgg, leon, linux-rdma; +Cc: linux-kernel, Li Zhijian, Bob Pearson

In the error path, both rxe_put(pd) and rxe_cleanup(mr) will
drop pd's ref_cont.
rxe_cleanup(mr)
 -> __rxe_cleanup
   -> rxe_put(mr->elem)
   -> rxe_mr_cleanup(mr)
     -> rxe_put(mr_pd(mr))

[342431.583189] ------------[ cut here ]------------
[342431.585051] refcount_t: underflow; use-after-free.
[342431.586677] WARNING: CPU: 0 PID: 660500 at lib/refcount.c:28 refcount_warn_saturate+0xcd/0x120
[342431.605247] RIP: 0010:refcount_warn_saturate+0xcd/0x120
[342431.661981]  __rxe_cleanup+0x1c3/0x1e0 [rdma_rxe]
[342431.663260]  rxe_dealloc_pd+0x16/0x20 [rdma_rxe]
[342431.664883]  ib_dealloc_pd_user+0x95/0xd0 [ib_core]
[342431.666803]  destroy_hw_idr_uobject+0x46/0x90 [ib_uverbs]
[342431.668514]  uverbs_destroy_uobject+0xc8/0x360 [ib_uverbs]
[342431.670232]  __uverbs_cleanup_ufile+0x157/0x210 [ib_uverbs]
[342431.671920]  ? uverbs_destroy_uobject+0x360/0x360 [ib_uverbs]

CC: Bob Pearson <rpearsonhpe@gmail.com>
Fixes: 0d0e4b528c3b ("RDMA/rxe: Set pd early in mr alloc routines")
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
I have to say i made a mistake in previous review, I missed this WARN_ONCE messages.
And the V6 patch that i had applied fix this problem in another way.
---
 drivers/infiniband/sw/rxe/rxe_verbs.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c
index 933277d67b7c..88825edc7dce 100644
--- a/drivers/infiniband/sw/rxe/rxe_verbs.c
+++ b/drivers/infiniband/sw/rxe/rxe_verbs.c
@@ -939,7 +939,6 @@ static struct ib_mr *rxe_reg_user_mr(struct ib_pd *ibpd,
 	return &mr->ibmr;
 
 err3:
-	rxe_put(pd);
 	rxe_cleanup(mr);
 err2:
 	return ERR_PTR(err);
@@ -974,7 +973,6 @@ static struct ib_mr *rxe_alloc_mr(struct ib_pd *ibpd, enum ib_mr_type mr_type,
 	return &mr->ibmr;
 
 err2:
-	rxe_put(pd);
 	rxe_cleanup(mr);
 err1:
 	return ERR_PTR(err);
-- 
2.31.1


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

* Re: [PATCH jgg-for-next] RDMA/rxe: Fix pd refcount_t: underflow; use-after-free
  2022-09-27  5:25 [PATCH jgg-for-next] RDMA/rxe: Fix pd refcount_t: underflow; use-after-free Li Zhijian
@ 2022-09-27 13:14 ` Jason Gunthorpe
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Gunthorpe @ 2022-09-27 13:14 UTC (permalink / raw)
  To: Li Zhijian; +Cc: zyjzyj2000, leon, linux-rdma, linux-kernel, Bob Pearson

On Tue, Sep 27, 2022 at 01:25:30PM +0800, Li Zhijian wrote:
> In the error path, both rxe_put(pd) and rxe_cleanup(mr) will
> drop pd's ref_cont.
> rxe_cleanup(mr)
>  -> __rxe_cleanup
>    -> rxe_put(mr->elem)
>    -> rxe_mr_cleanup(mr)
>      -> rxe_put(mr_pd(mr))
> 
> [342431.583189] ------------[ cut here ]------------
> [342431.585051] refcount_t: underflow; use-after-free.
> [342431.586677] WARNING: CPU: 0 PID: 660500 at lib/refcount.c:28 refcount_warn_saturate+0xcd/0x120
> [342431.605247] RIP: 0010:refcount_warn_saturate+0xcd/0x120
> [342431.661981]  __rxe_cleanup+0x1c3/0x1e0 [rdma_rxe]
> [342431.663260]  rxe_dealloc_pd+0x16/0x20 [rdma_rxe]
> [342431.664883]  ib_dealloc_pd_user+0x95/0xd0 [ib_core]
> [342431.666803]  destroy_hw_idr_uobject+0x46/0x90 [ib_uverbs]
> [342431.668514]  uverbs_destroy_uobject+0xc8/0x360 [ib_uverbs]
> [342431.670232]  __uverbs_cleanup_ufile+0x157/0x210 [ib_uverbs]
> [342431.671920]  ? uverbs_destroy_uobject+0x360/0x360 [ib_uverbs]
> 
> CC: Bob Pearson <rpearsonhpe@gmail.com>
> Fixes: 0d0e4b528c3b ("RDMA/rxe: Set pd early in mr alloc routines")
> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
> ---
> I have to say i made a mistake in previous review, I missed this WARN_ONCE messages.
> And the V6 patch that i had applied fix this problem in another way.

Does this mean I took the wrong patch? The patchworks got messed up
for this series somehow

I'll squash this diff in..

Jason

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

end of thread, other threads:[~2022-09-27 13:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-27  5:25 [PATCH jgg-for-next] RDMA/rxe: Fix pd refcount_t: underflow; use-after-free Li Zhijian
2022-09-27 13:14 ` Jason Gunthorpe

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).