lkml.org 
[lkml]   [2022]   [Jan]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2] RDMA/rxe: Prevent from double freeing rxe_map_set
On Tue, Dec 28, 2021 at 09:44:06AM +0800, Li Zhijian wrote:
> a 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
>
> By convention, we should cleanup/free resources in the error path in the
> same function where the resources are alloted in. So rxe_mr_init_user()
> doesn't need to free the map_set directly.
>
> In addition, we have to reset map_set to NULL inside rxe_mr_alloc() if needed
> to prevent from map_set being double freed in rxe_mr_cleanup().
>
> CC: Jason Gunthorpe <jgg@nvidia.com>
> Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
> Acked-by: Zhu Yanjun <zyjzyj2000@gmail.com>
> ---
> V2: Fix it by a simpler way by following suggestion from Bob,
> ---
> drivers/infiniband/sw/rxe/rxe_mr.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)

Applied to for-rc, but I changed it to keep the goto unwind as is
normal.

@@ -135,19 +135,19 @@ static int rxe_mr_alloc(struct rxe_mr *mr, int num_buf, int both)

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

if (both) {
ret = rxe_mr_alloc_map_set(num_map, &mr->next_map_set);
- if (ret) {
- rxe_mr_free_map_set(mr->num_map, mr->cur_map_set);
- goto err_out;
- }
+ if (ret)
+ goto err_free;
}

return 0;

-err_out:
+err_free:
+ rxe_mr_free_map_set(mr->num_map, mr->cur_map_set);
+ mr->cur_map_set = NULL;
return -ENOMEM;
}

\
 
 \ /
  Last update: 2022-01-05 01:45    [W:0.070 / U:0.016 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site