Skip to contentSkip to conversation

RDMA/ocrdma: fix use after free in ocrdma_dealloc_ucontext_pd()

PATCH Applied [email protected] 4 participants 5 messages Dec 30, 2020 – Jan 11, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/ocrdma: fix use after free in ocrdma_dealloc_ucontext_pd()

From: Tom Rix <[email protected]>

In ocrdma_dealloc_ucontext_pd() uctx->cntxt_pd is assigned to the variable pd and then after uctx->cntxt_pd is freed, the variable pd is passed to function _ocrdma_dealloc_pd() which dereferences pd directly or through its call to ocrdma_mbx_dealloc_pd().

Reorder the free using the variable pd.

Fixes 21a428a019c9 ("RDMA: Handle PD allocations by IB/core")
---
 drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +1 -1
index bc98bd950d99..3acb5c10b155 100644
@@ -434,9 +434,9 @@ static void ocrdma_dealloc_ucontext_pd(struct ocrdma_ucontext *uctx)
 		pr_err("%s(%d) Freeing in use pdid=0x%x.\n",
 		       __func__, dev->id, pd->id);
 	}
-	kfree(uctx->cntxt_pd);
 	uctx->cntxt_pd = NULL;
 	_ocrdma_dealloc_pd(dev, pd);
+	kfree(pd);
 }
 
 static struct ocrdma_pd *ocrdma_get_ucontext_pd(struct ocrdma_ucontext *uctx)
Signature · 1 line
2.27.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · On Tue, Dec 29, 2020 at 06:46:53PM -0800, [email protected] wrote:

From: Tom Rix <[email protected]>

In ocrdma_dealloc_ucontext_pd() uctx->cntxt_pd is assigned to the variable pd and then after uctx->cntxt_pd is freed, the variable pd is passed to function _ocrdma_dealloc_pd() which dereferences pd directly or through its call to ocrdma_mbx_dealloc_pd().

Quoted 8 lines

Reorder the free using the variable pd.

Fixes 21a428a019c9 ("RDMA: Handle PD allocations by IB/core")
---
 drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Thanks,

maintainer Applied
#2 lore raw
In reply to [email protected]
Quoted 8 lines · On Tue, Dec 29, 2020 at 06:46:53PM -0800, [email protected] wrote:

From: Tom Rix <[email protected]>

In ocrdma_dealloc_ucontext_pd() uctx->cntxt_pd is assigned to the variable pd and then after uctx->cntxt_pd is freed, the variable pd is passed to function _ocrdma_dealloc_pd() which dereferences pd directly or through its call to ocrdma_mbx_dealloc_pd().

Quoted 6 lines

Reorder the free using the variable pd.

Fixes 21a428a019c9 ("RDMA: Handle PD allocations by IB/core")
 drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to for-rc

Is anyone testing ocrdma? Just doing the pyverbs rdma tests with kasn turned on would have instantly caught this, and the change is nearly a year old.

Is ocrdma obsolete enough we can delete the driver?

Thanks,
Jason

author
#3 lore raw
Quoted 15 lines · Jason Gunthorpe
Quoted 8 lines · On Tue, Dec 29, 2020 at 06:46:53PM -0800, [email protected] wrote:

From: Tom Rix <[email protected]>

In ocrdma_dealloc_ucontext_pd() uctx->cntxt_pd is assigned to the variable pd and then after uctx->cntxt_pd is freed, the variable pd is passed to function _ocrdma_dealloc_pd() which dereferences pd directly or through its call to ocrdma_mbx_dealloc_pd().

Quoted 6 lines

Reorder the free using the variable pd.

Fixes 21a428a019c9 ("RDMA: Handle PD allocations by IB/core")
 drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 7 lines

Applied to for-rc

Is anyone testing ocrdma? Just doing the pyverbs rdma tests with kasn turned on would have instantly caught this, and the change is nearly a year old.

Is ocrdma obsolete enough we can delete the driver?

I am not an authority on ocrdma, i am fixing treewide, the problems clang static analysis flags.

Tom

Quoted 4 lines

Thanks,
Jason

maintainer
#4 lore raw
Quoted 18 lines · Tom Rix
Quoted 15 lines · Jason Gunthorpe
Quoted 14 lines · On Tue, Dec 29, 2020 at 06:46:53PM -0800, [email protected] wrote:

From: Tom Rix <[email protected]>

In ocrdma_dealloc_ucontext_pd() uctx->cntxt_pd is assigned to the variable pd and then after uctx->cntxt_pd is freed, the variable pd is passed to function _ocrdma_dealloc_pd() which dereferences pd directly or through its call to ocrdma_mbx_dealloc_pd().

Reorder the free using the variable pd.

Fixes 21a428a019c9 ("RDMA: Handle PD allocations by IB/core")
 drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 7 lines
Quoted 7 lines

Applied to for-rc

Is anyone testing ocrdma? Just doing the pyverbs rdma tests with kasn turned on would have instantly caught this, and the change is nearly a year old.

Is ocrdma obsolete enough we can delete the driver?

Broadcom is not doing any active development/testing with ocrdma now. I am checking with other teams to see if this can be deleted completely. Will get back asap.

Thanks,
Selvin

Quoted 10 lines

I am not an authority on ocrdma, i am fixing treewide, the problems clang static analysis flags.

Tom

Quoted 4 lines

Thanks,
Jason