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 E86382D0C75; Sat, 12 Sep 2026 12:25:40 +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=1789215942; cv=none; b=hFrrYmK+iRGy2FnNVHKj1/32DqciWH5a6qSRPuRjIoAtdb0IiUYVXZXqtaC2l8gGy7cOUrEi7LdWQXDn5xfR64ouiUxKRIYF0I9nJ7KujocE01NlIy8/dpuH2SZKq8NA+jGKDL5R3xSczNjww/8OOWSP6vIM/SVSTP2WPeNQ4jU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789215942; c=relaxed/simple; bh=uc7BBhwMnSU9H2AcFndZjYRS6cL+DZPAsHniIyOWP6A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s4k5dooVkbIxsODjULbgKZ23Xb55/4KrVEFO191fZUkVAunPM1q/+u7feOs+MnAkK1DTaYY1t/I63pwq6X4Z/Br8ouhP5wBNoxZz+Fc9snoWRJ7BbZepzIrb+mZcTteHHIRoE/tiz/VO5K8WmdHce4IIGVSBct+Lh/0u+dKn3zg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=wEJw+gwW; 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="wEJw+gwW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1D8E1F000FF; Sat, 12 Sep 2026 12:25:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789215940; bh=toKt6lpCeBYlxhyajfeYQEVF7ZlnaYpiP9ppXi7vuOA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=wEJw+gwWa6S/SDm6kLIjylLZyXSkzlT1kJDdFtz0Wg/bt45U7IxSpYAAcHMYD9yy0 wkWKpc+oShonqFnd/a+8SazErvuPNpEYwc6sXIHab7TdYhocjuxz/8oXROaY6GYKAZ OoXLth+trbzU646mu0IIQz/66qK98HA956QVGVC0= 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 6.12 0634/1376] RDMA/core: Fix potential use after free in counter_release() Date: Sat, 12 Sep 2026 08:51:00 +0200 Message-ID: <20260912065621.672004815@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065607.535295758@linuxfoundation.org> References: <20260912065607.535295758@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 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Patrisious Haddad [ Upstream commit 235ef2d0e750885c29340b0fc40620a7a4f52e12 ] When accessing a counter via the netlink path the only synchronization mechanism for the said counter is rdma_restrack_get(). Currently, rdma_restrack_del() is invoked at the end of counter_release(), which is too late, since by that point vendor-specific resources associated with the counter might already be freed. This can leave a short window where the counter 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 counter is removed from restrack before its internal resources are released. This guarantees that no new users hold references to a counter that is in the process of destruction. Fixes: 99fa331dc862 ("RDMA/counter: Add "auto" configuration mode support") 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-5-bbe8bb270d51@nvidia.com Signed-off-by: Leon Romanovsky Signed-off-by: Sasha Levin --- drivers/infiniband/core/counters.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/core/counters.c b/drivers/infiniband/core/counters.c index d41af5ab6403a..8cbca897fc531 100644 --- a/drivers/infiniband/core/counters.c +++ b/drivers/infiniband/core/counters.c @@ -217,7 +217,6 @@ static void rdma_counter_free(struct rdma_counter *counter) mutex_unlock(&port_counter->lock); - rdma_restrack_del(&counter->res); rdma_free_hw_stats_struct(counter->stats); kfree(counter); } @@ -312,6 +311,7 @@ static void counter_release(struct kref *kref) counter = container_of(kref, struct rdma_counter, kref); counter_history_stat_update(counter); + rdma_restrack_del(&counter->res); counter->device->ops.counter_dealloc(counter); rdma_counter_free(counter); } @@ -472,7 +472,8 @@ static struct rdma_counter *rdma_get_counter_by_id(struct ib_device *dev, return NULL; counter = container_of(res, struct rdma_counter, res); - kref_get(&counter->kref); + if (!kref_get_unless_zero(&counter->kref)) + counter = NULL; rdma_restrack_put(res); return counter; -- 2.53.0