From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 2D3C53AF646; Sat, 12 Sep 2026 18:50:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789239013; cv=none; b=a0iJaGD4W/c4QbnwMTdVhlKPkwDT3qGfvn+kA7q6PMCi5XrfZG7y1c3jLLXM1U6fU7N56OnV/TZL8gPzpnK2kfHZq8sikg0Ze7vfLj8KlsQnUh2Kpsb8uXJXxcxeemB7vVqDac1t7UE1vVtWohK/ovppaqbPhdiXk7amPgCvk/w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789239013; c=relaxed/simple; bh=Gz0gvWUfCoP5EiyV8AuE2+9vqQn3BGzFXxaHIvIlxwA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VaXmR+xhXDXX8nxVs1OYTyQjyVk+biOMTaIe5OegvE5bD3XCPuZEX7eZVNahXIJP6GFs3arXbXeJLHIvuYJDxC9vAXjVMiX6r+1G7acOYsLkzP2iJqXZsM7BJ3PY7zDgXgvZgYb9boU/Vp6irWZKooYOmdSlOaTm6O0ViyjUqFY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ZQyivbVp; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ZQyivbVp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C95131F000FF; Sat, 12 Sep 2026 18:50:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789239012; bh=+YP99FZLzwmXMl0+/kBkiljbnQrFcocNPn2jd/L6mpk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZQyivbVpuBJhiFp7wlqihBQNg4QnJi0MmR43F1Vq316xl2nckcOBPnNw/QONefsTA Zzd53+pTT1TWkvdBZfBYadx4tjUY1QJdgSsCwe6l/gfY7ujjs0kM4/Goxr243xvd3f rJt0ZKWfjUIhcRPjyCSRnlUFPrJ6xGzf5X1ThJ+M= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Patrisious Haddad , Michael Guralnik , Edward Srouji , Leon Romanovsky , Sasha Levin Subject: [PATCH 5.15 576/935] RDMA/core: Fix potential use after free in ib_free_cq() Date: Sat, 12 Sep 2026 09:00:06 +0200 Message-ID: <20260912065540.049808879@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065526.833703348@linuxfoundation.org> References: <20260912065526.833703348@linuxfoundation.org> User-Agent: quilt/0.69 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 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Patrisious Haddad [ Upstream commit 29dc2f8e1c97372c2871a70088707933515fbd5b ] When accessing a CQ via the netlink path the only synchronization mechanism for the said CQ is rdma_restrack_get(). Currently, rdma_restrack_del() is invoked at the end of ib_free_cq(), which is too late, since by that point vendor-specific resources associated with the CQ might already be freed. This can leave a short window where the CQ remains accessible through restrack, leading to a potential use-after-free. Fix this by moving the rdma_restrack_del() call to be before the freeing of the vendor-specific resources ensuring that the CQ is removed from restrack before its internal resources are released. This guarantees that no new users hold references to a CQ that is in the process of destruction. Fixes: 43d781b9fa56 ("RDMA: Allow fail of destroy CQ") Signed-off-by: Patrisious Haddad Reviewed-by: Michael Guralnik Signed-off-by: Edward Srouji Link: https://patch.msgid.link/20260713-restrack-uaf-fix-resub-v2-6-bbe8bb270d51@nvidia.com Signed-off-by: Leon Romanovsky Signed-off-by: Sasha Levin --- drivers/infiniband/core/cq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/core/cq.c b/drivers/infiniband/core/cq.c index aa499d722ae26..6b5a53beeafb7 100644 --- a/drivers/infiniband/core/cq.c +++ b/drivers/infiniband/core/cq.c @@ -325,6 +325,7 @@ void ib_free_cq(struct ib_cq *cq) if (WARN_ON_ONCE(cq->cqe_used)) return; + rdma_restrack_del(&cq->res); if (cq->device->ops.pre_destroy_cq) { ret = cq->device->ops.pre_destroy_cq(cq); WARN_ONCE(ret, "Disable of kernel CQ shouldn't fail"); @@ -351,7 +352,6 @@ void ib_free_cq(struct ib_cq *cq) else ret = cq->device->ops.destroy_cq(cq, NULL); WARN_ONCE(ret, "Destroy of kernel CQ shouldn't fail"); - rdma_restrack_del(&cq->res); kfree(cq->wc); kfree(cq); } -- 2.53.0