Skip to content

Commit 8ff5f5d

Browse files
zhijianli88jgunthorpe
authored andcommitted
RDMA/rxe: Prevent double freeing rxe_map_set()
The same rxe_map_set could be freed twice: rxe_reg_user_mr() -> rxe_mr_init_user() -> rxe_mr_free_map_set() # 1st -> rxe_drop_ref() ... -> rxe_mr_cleanup() -> rxe_mr_free_map_set() # 2nd Follow normal convection and put resource cleanup either in the error unwind of the allocator, or the overall free function. Leave the object unchanged with a NULL cur_map_set on failure and remove the unncessary free in rxe_mr_init_user(). Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Li Zhijian <[email protected]> Acked-by: Zhu Yanjun <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent c9e6606 commit 8ff5f5d

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

drivers/infiniband/sw/rxe/rxe_mr.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,19 @@ static int rxe_mr_alloc(struct rxe_mr *mr, int num_buf, int both)
135135

136136
ret = rxe_mr_alloc_map_set(num_map, &mr->cur_map_set);
137137
if (ret)
138-
goto err_out;
138+
return -ENOMEM;
139139

140140
if (both) {
141141
ret = rxe_mr_alloc_map_set(num_map, &mr->next_map_set);
142-
if (ret) {
143-
rxe_mr_free_map_set(mr->num_map, mr->cur_map_set);
144-
goto err_out;
145-
}
142+
if (ret)
143+
goto err_free;
146144
}
147145

148146
return 0;
149147

150-
err_out:
148+
err_free:
149+
rxe_mr_free_map_set(mr->num_map, mr->cur_map_set);
150+
mr->cur_map_set = NULL;
151151
return -ENOMEM;
152152
}
153153

@@ -214,7 +214,7 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova,
214214
pr_warn("%s: Unable to get virtual address\n",
215215
__func__);
216216
err = -ENOMEM;
217-
goto err_cleanup_map;
217+
goto err_release_umem;
218218
}
219219

220220
buf->addr = (uintptr_t)vaddr;
@@ -237,8 +237,6 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova,
237237

238238
return 0;
239239

240-
err_cleanup_map:
241-
rxe_mr_free_map_set(mr->num_map, mr->cur_map_set);
242240
err_release_umem:
243241
ib_umem_release(umem);
244242
err_out:

0 commit comments

Comments
 (0)