提交 a79db264 编写于 作者: J Jianglei Nie 提交者: Zheng Zengkai

RDMA/hfi1: fix potential memory leak in setup_base_ctxt()

stable inclusion
from stable-v5.10.137
commit a85c7dd1edadcdeca24e603a6618153a3bcc81ca
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I60PLB

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=a85c7dd1edadcdeca24e603a6618153a3bcc81ca

--------------------------------

[ Upstream commit aa2a1df3 ]

setup_base_ctxt() allocates a memory chunk for uctxt->groups with
hfi1_alloc_ctxt_rcv_groups(). When init_user_ctxt() fails, uctxt->groups
is not released, which will lead to a memory leak.

We should release the uctxt->groups with hfi1_free_ctxt_rcv_groups()
when init_user_ctxt() fails.

Fixes: e87473bc ("IB/hfi1: Only set fd pointer when base context is completely initialized")
Link: https://lore.kernel.org/r/20220711070718.2318320-1-niejianglei2021@163.comSigned-off-by: NJianglei Nie <niejianglei2021@163.com>
Acked-by: NDennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
Signed-off-by: NLeon Romanovsky <leon@kernel.org>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Reviewed-by: NWei Li <liwei391@huawei.com>
上级 b3afad51
...@@ -1220,8 +1220,10 @@ static int setup_base_ctxt(struct hfi1_filedata *fd, ...@@ -1220,8 +1220,10 @@ static int setup_base_ctxt(struct hfi1_filedata *fd,
goto done; goto done;
ret = init_user_ctxt(fd, uctxt); ret = init_user_ctxt(fd, uctxt);
if (ret) if (ret) {
hfi1_free_ctxt_rcv_groups(uctxt);
goto done; goto done;
}
user_init(uctxt); user_init(uctxt);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册