From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4201B1ABEB7; Mon, 14 Oct 2024 15:01:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728918096; cv=none; b=pqO/pPRe/OwjyY43ksTN/pB/vGWf3OGKJrjJwbI8X+yuLl9y8ddRI1LWe4U9rNix9NniYbt3KJl1rozmpBW24xGfNfDwWinFJjQu0srL6WVxABv37DBqFLeQpkRLu0yn90lxYtOYjNiYjuVwBcaVmJXTxglU05GBOUe1pZfD2E8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728918096; c=relaxed/simple; bh=M0Yr93ftA50JzKFlvo5ynrx2dJHKYWZE3PByOrrEmzE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P4hDPjaPdiuccUbVK/+Sws1TECV5ySKmYKiqEmfDmENMhXWpxfVaHW08/Lq9ArwxshD6R9YTj2X+FU3EycBYFdIWCmXe+WXrGUQFp7pkB8tvHYb1zmNwn63EpUDREwWB84OmdU0hoVu2DClpDYE48Q6+U040psF8tDf+URevwKA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=knFcmN2v; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="knFcmN2v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEB79C4CEC3; Mon, 14 Oct 2024 15:01:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1728918096; bh=M0Yr93ftA50JzKFlvo5ynrx2dJHKYWZE3PByOrrEmzE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=knFcmN2vqB2M19d0DVjA9b8onJkNoIwmUY3uQpLOB232fL+B1hDqOZoiRW1TC/EPY 0PRgqZD0h4uP7URa0hqaEKC+0zhOEF9d7V8sKw7xh+IUaoG6291/pLE7c8eNVwC7I6 86jhRdi24xy23dAj6qnMASJCYOxxVmhqzC/nUN0s= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, wenglianfa , Junxian Huang , Leon Romanovsky , Sasha Levin Subject: [PATCH 6.1 220/798] RDMA/hns: Fix Use-After-Free of rsv_qp on HIP08 Date: Mon, 14 Oct 2024 16:12:54 +0200 Message-ID: <20241014141226.572007981@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241014141217.941104064@linuxfoundation.org> References: <20241014141217.941104064@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: wenglianfa [ Upstream commit fd8489294dd2beefb70f12ec4f6132aeec61a4d0 ] Currently rsv_qp is freed before ib_unregister_device() is called on HIP08. During the time interval, users can still dereg MR and rsv_qp will be used in this process, leading to a UAF. Move the release of rsv_qp after calling ib_unregister_device() to fix it. Fixes: 70f92521584f ("RDMA/hns: Use the reserved loopback QPs to free MR before destroying MPT") Signed-off-by: wenglianfa Signed-off-by: Junxian Huang Link: https://patch.msgid.link/20240906093444.3571619-3-huangjunxian6@hisilicon.com Signed-off-by: Leon Romanovsky Signed-off-by: Sasha Levin --- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c index 3318d27233e0d..7ca85dcb5458c 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c @@ -3058,6 +3058,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) @@ -6935,9 +6938,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); kfree(hr_dev->priv); ib_dealloc_device(&hr_dev->ib_dev); -- 2.43.0