2021-03-11 05:46:31

by Lv Yunlong

[permalink] [raw]
Subject: [PATCH] nvme/rdma: Fix a use after free in nvmet_rdma_write_data_done

In nvmet_rdma_write_data_done, rsp is recoverd by wc->wr_cqe
and freed by nvmet_rdma_release_rsp(). But after that, pr_info()
used the freed chunk's member object and could leak the freed
chunk address with wc->wr_cqe by computing the offset.

Signed-off-by: Lv Yunlong <[email protected]>
---
drivers/nvme/target/rdma.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c
index 06b6b742bb21..6c1f3ab7649c 100644
--- a/drivers/nvme/target/rdma.c
+++ b/drivers/nvme/target/rdma.c
@@ -802,9 +802,8 @@ static void nvmet_rdma_write_data_done(struct ib_cq *cq, struct ib_wc *wc)
nvmet_req_uninit(&rsp->req);
nvmet_rdma_release_rsp(rsp);
if (wc->status != IB_WC_WR_FLUSH_ERR) {
- pr_info("RDMA WRITE for CQE 0x%p failed with status %s (%d).\n",
- wc->wr_cqe, ib_wc_status_msg(wc->status),
- wc->status);
+ pr_info("RDMA WRITE for CQE failed with status %s (%d).\n",
+ ib_wc_status_msg(wc->status), wc->status);
nvmet_rdma_error_comp(queue);
}
return;
--
2.25.1



2021-03-15 17:21:53

by Sagi Grimberg

[permalink] [raw]
Subject: Re: [PATCH] nvme/rdma: Fix a use after free in nvmet_rdma_write_data_done


> In nvmet_rdma_write_data_done, rsp is recoverd by wc->wr_cqe
> and freed by nvmet_rdma_release_rsp(). But after that, pr_info()
> used the freed chunk's member object and could leak the freed
> chunk address with wc->wr_cqe by computing the offset.
>
> Signed-off-by: Lv Yunlong <[email protected]>
> ---
> drivers/nvme/target/rdma.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c
> index 06b6b742bb21..6c1f3ab7649c 100644
> --- a/drivers/nvme/target/rdma.c
> +++ b/drivers/nvme/target/rdma.c
> @@ -802,9 +802,8 @@ static void nvmet_rdma_write_data_done(struct ib_cq *cq, struct ib_wc *wc)
> nvmet_req_uninit(&rsp->req);
> nvmet_rdma_release_rsp(rsp);
> if (wc->status != IB_WC_WR_FLUSH_ERR) {
> - pr_info("RDMA WRITE for CQE 0x%p failed with status %s (%d).\n",
> - wc->wr_cqe, ib_wc_status_msg(wc->status),
> - wc->status);
> + pr_info("RDMA WRITE for CQE failed with status %s (%d).\n",
> + ib_wc_status_msg(wc->status), wc->status);

There is nothing wrong with this reference, wr_cqe is a valid reference
and I think Israel added this for some extra information that may be
useful to him.

Israel? you ok with this removed?

> nvmet_rdma_error_comp(queue);
> }
> return;
>