Commit ec799ad0 authored by wenglianfa's avatar wenglianfa Committed by Juan Zhou
Browse files

RDMA/hns: Fix Use-After-Free of rsv_qp

driver inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I8N7BG



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

For the HIP08, the reserved loopback QP is used to release MRs
before the MPT is destroyed. After free_mr_exit() and before
hns_roce_unregister_device(), rsv_qp is released and set to NULL,
and ib_device is not unregister. During this period, the user mode
can use ib_device to execute dereg_mr(). As a result, rsv_qp is
accessed again and a NULL pointer is reported.

To fix Use-After-Free of rsv_qp, execute free_mr_exit() after
hns_roce_unregister_device().

Fixes: 6f5f556d ("RDMA/hns: Use the reserved loopback QPs to free MR before destroying MPT")
Signed-off-by: default avatarwenglianfa <wenglianfa@huawei.com>
Signed-off-by: default avatarJuan Zhou <zhoujuan51@h-partners.com>
parent 4c5c7875
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -3339,6 +3339,9 @@ static int hns_roce_v2_init(struct hns_roce_dev *hr_dev)

static void hns_roce_v2_exit(struct hns_roce_dev *hr_dev)
{
	if (hr_dev->pci_dev->revision == PCI_REVISION_ID_HIP08)
		free_mr_exit(hr_dev);

	hns_roce_function_clear(hr_dev);

	if (!hr_dev->is_vf)
@@ -7700,9 +7703,6 @@ static void __hns_roce_hw_v2_uninit_instance(struct hnae3_handle *handle,
	hr_dev->state = HNS_ROCE_DEVICE_STATE_UNINIT;
	hns_roce_handle_device_err(hr_dev);

	if (hr_dev->pci_dev->revision == PCI_REVISION_ID_HIP08)
		free_mr_exit(hr_dev);

	hns_roce_exit(hr_dev, bond_cleanup);
	kfree(hr_dev->priv);
	ib_dealloc_device(&hr_dev->ib_dev);