Skip to content

Commit 6ce577f

Browse files
zhijianli88gregkh
authored andcommitted
RDMA/rxe: Fix mr->map double free
[ Upstream commit 7d984da ] rxe_mr_cleanup() which tries to free mr->map again will be called when rxe_mr_init_user() fails: CPU: 0 PID: 4917 Comm: rdma_flush_serv Kdump: loaded Not tainted 6.1.0-rc1-roce-flush+ #25 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0x45/0x5d panic+0x19e/0x349 end_report.part.0+0x54/0x7c kasan_report.cold+0xa/0xf rxe_mr_cleanup+0x9d/0xf0 [rdma_rxe] __rxe_cleanup+0x10a/0x1e0 [rdma_rxe] rxe_reg_user_mr+0xb7/0xd0 [rdma_rxe] ib_uverbs_reg_mr+0x26a/0x480 [ib_uverbs] ib_uverbs_handler_UVERBS_METHOD_INVOKE_WRITE+0x1a2/0x250 [ib_uverbs] ib_uverbs_cmd_verbs+0x1397/0x15a0 [ib_uverbs] This issue was firstly exposed since commit b18c7da ("RDMA/rxe: Fix memory leak in error path code") and then we fixed it in commit 8ff5f5d ("RDMA/rxe: Prevent double freeing rxe_map_set()") but this fix was reverted together at last by commit 1e75550 (Revert "RDMA/rxe: Create duplicate mapping tables for FMRs") Simply let rxe_mr_cleanup() always handle freeing the mr->map once it is successfully allocated. Fixes: 1e75550 ("Revert "RDMA/rxe: Create duplicate mapping tables for FMRs"") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Li Zhijian <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 8236445 commit 6ce577f

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

drivers/infiniband/sw/rxe/rxe_mr.c

+2-7
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ static int rxe_mr_alloc(struct rxe_mr *mr, int num_buf)
9999
kfree(mr->map[i]);
100100

101101
kfree(mr->map);
102+
mr->map = NULL;
102103
err1:
103104
return -ENOMEM;
104105
}
@@ -122,7 +123,6 @@ int rxe_mr_init_user(struct rxe_dev *rxe, u64 start, u64 length, u64 iova,
122123
int num_buf;
123124
void *vaddr;
124125
int err;
125-
int i;
126126

127127
umem = ib_umem_get(&rxe->ib_dev, start, length, access);
128128
if (IS_ERR(umem)) {
@@ -163,9 +163,8 @@ int rxe_mr_init_user(struct rxe_dev *rxe, u64 start, u64 length, u64 iova,
163163
pr_warn("%s: Unable to get virtual address\n",
164164
__func__);
165165
err = -ENOMEM;
166-
goto err_cleanup_map;
166+
goto err_release_umem;
167167
}
168-
169168
buf->addr = (uintptr_t)vaddr;
170169
buf->size = PAGE_SIZE;
171170
num_buf++;
@@ -185,10 +184,6 @@ int rxe_mr_init_user(struct rxe_dev *rxe, u64 start, u64 length, u64 iova,
185184

186185
return 0;
187186

188-
err_cleanup_map:
189-
for (i = 0; i < mr->num_map; i++)
190-
kfree(mr->map[i]);
191-
kfree(mr->map);
192187
err_release_umem:
193188
ib_umem_release(umem);
194189
err_out:

0 commit comments

Comments
 (0)