]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commit
RDMA/siw: Fix a use after free in siw_alloc_mr
authorLv Yunlong <lyl2019@mail.ustc.edu.cn>
Mon, 26 Apr 2021 01:16:47 +0000 (18:16 -0700)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 26 May 2021 13:39:24 +0000 (15:39 +0200)
commita0675ce6d83347d5372c70578ead773b62ad5268
tree7b16da03fed653b22d0e2c1ffbe696471a58a25d
parente2b9fb86216c1d0593ffad0195e03c7ae60ff3af
RDMA/siw: Fix a use after free in siw_alloc_mr

BugLink: https://bugs.launchpad.net/bugs/1929615
[ Upstream commit 3093ee182f01689b89e9f8797b321603e5de4f63 ]

Our code analyzer reported a UAF.

In siw_alloc_mr(), it calls siw_mr_add_mem(mr,..). In the implementation of
siw_mr_add_mem(), mem is assigned to mr->mem and then mem is freed via
kfree(mem) if xa_alloc_cyclic() failed. Here, mr->mem still point to a
freed object. After, the execution continue up to the err_out branch of
siw_alloc_mr, and the freed mr->mem is used in siw_mr_drop_mem(mr).

My patch moves "mr->mem = mem" behind the if (xa_alloc_cyclic(..)<0) {}
section, to avoid the uaf.

Fixes: 2251334dcac9 ("rdma/siw: application buffer management")
Link: https://lore.kernel.org/r/20210426011647.3561-1-lyl2019@mail.ustc.edu.cn
Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
Reviewed-by: Bernard Metzler <bmt@zurich.ihm.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
drivers/infiniband/sw/siw/siw_mem.c