From: "lizhijian@fujitsu.com" <lizhijian@fujitsu.com>
To: Yanjun Zhu <yanjun.zhu@linux.dev>,
"zyjzyj2000@gmail.com" <zyjzyj2000@gmail.com>,
"jgg@ziepe.ca" <jgg@ziepe.ca>,
"leon@kernel.org" <leon@kernel.org>,
"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>
Cc: Bob Pearson <rpearsonhpe@gmail.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH for-next v2] RDMA/rxe: Fix mr->map double free
Date: Wed, 16 Nov 2022 02:39:14 +0000 [thread overview]
Message-ID: <e8490cd3-36d1-3471-bb18-ba8d0c9d4aac@fujitsu.com> (raw)
In-Reply-To: <c1fa0a0c-d8f3-f6c4-7964-3bb31ac936ff@linux.dev>
On 16/11/2022 08:10, Yanjun Zhu wrote:
>>
>> index d4f10c2d1aa7..7c99d1591580 100644
>> --- a/drivers/infiniband/sw/rxe/rxe_mr.c
>> +++ b/drivers/infiniband/sw/rxe/rxe_mr.c
>> @@ -99,6 +99,7 @@ static int rxe_mr_alloc(struct rxe_mr *mr, int num_buf)
>> kfree(mr->map[i]);
>> kfree(mr->map);
>> + mr->map = NULL;
>> err1:
>> return -ENOMEM;
>> }
>> @@ -122,7 +123,6 @@ int rxe_mr_init_user(struct rxe_dev *rxe, u64
>> start, u64 length, u64 iova,
>> int num_buf;
>> void *vaddr;
>> int err;
>> - int i;
>> umem = ib_umem_get(&rxe->ib_dev, start, length, access);
>> if (IS_ERR(umem)) {
>> @@ -163,9 +163,8 @@ int rxe_mr_init_user(struct rxe_dev *rxe, u64
>> start, u64 length, u64 iova,
>> pr_warn("%s: Unable to get virtual address\n",
>> __func__);
>> err = -ENOMEM;
>> - goto err_cleanup_map;
>> + goto err_release_umem;
>
> This call trace results from page_address's returning NULL, then goto
> err_cleanup_map where mr->map[i] and mr->map are freed.
>
> And finally rxe_reg_user_mr gets an error from rxe_mr_init_user, the
> function rxe_mr_cleanup is called to handle mr to free mr->map[i] and
> mr->map again.
>
> So mr->map[i] and mr->map are double freed.
>
> As such, this commit is reasonable.
>
> But why page_address will return NULL?
ENOMEM? but I don't think we need taking too much care upon the reason.
this patch is most likely porting the reverted back, commit:
8ff5f5d9d8cf ("RDMA/rxe: Prevent double freeing rxe_map_set()")
Actually, the double free can be triggered by below error path too.
149 err = rxe_mr_alloc(mr, num_buf);
150 if (err) {
151 pr_warn("%s: Unable to allocate memory for map\n",
152 __func__);
153 goto err_release_umem;
154 }
where rxe_mr_alloc() freed the memory but don't set 'mr->map = NULL'
Thanks
Zhijian
>
> Zhu Yanjun
>
next prev parent reply other threads:[~2022-11-16 2:39 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-30 3:04 [PATCH for-next v2] RDMA/rxe: Fix mr->map double free Li Zhijian
2022-11-12 3:29 ` lizhijian
2022-11-13 12:40 ` Yanjun Zhu
2022-11-16 0:10 ` Yanjun Zhu
2022-11-16 2:39 ` lizhijian [this message]
2022-11-19 0:15 ` Jason Gunthorpe
2022-11-19 8:25 ` Yanjun Zhu
2022-11-20 1:29 ` [for-next PATCH 1/1] RDMA/rxe: sgt_append from ib_umem_get is not highmem Zhu Yanjun
2022-11-19 10:30 ` lizhijian
2022-11-19 13:20 ` Yanjun Zhu
2022-11-21 15:28 ` Jason Gunthorpe
2022-11-22 4:07 ` Yanjun Zhu
2022-11-22 14:06 ` Jason Gunthorpe
2022-11-23 1:53 ` Yanjun Zhu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e8490cd3-36d1-3471-bb18-ba8d0c9d4aac@fujitsu.com \
--to=lizhijian@fujitsu.com \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=rpearsonhpe@gmail.com \
--cc=yanjun.zhu@linux.dev \
--cc=zyjzyj2000@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox