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 2475D509F18; Wed, 30 Sep 2026 16:19:47 +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=1790785189; cv=none; b=Z31DJTONWhB4AlrlC2MhPEwYALJAQlVCPK878ZC5Z1u5fJsW0IHSR8qkdy45WzxPcb7MmeFGMnzqEExvIW03SlDAON9gqAB916HlbYspi2PFDwkx/+Ifk4mGO2OAGyRl5kgVq5C2mE/j5qtTOZ/kXDS2UPoB6LkPY/FMngeK0/E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790785189; c=relaxed/simple; bh=qBdS83I45ch2+B4ceZq8hRn3blOthspMOwOULT9TOEo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DB9qg4Mu1Gg5DcNJk33Rfgz9gkRA18jOvaPXENKQPLstyRgusHa4UOeE2dbuaZeLa/yqiHFO7wzdn8K7fejOs3IsC/ofWIjg7IwSBMcbcIBunXMP/I6m8NUZTLk65xhyhUmhqZdfqlm2Dzod+SekMZhf7UIbiB5oUnU1WyM3rjI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=grlGIRij; 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="grlGIRij" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB5C11F00899; Wed, 30 Sep 2026 16:19:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790785186; bh=SPrfeX9SjGSRh5n6+HP/YSz2kP+mXPF7cik7KAvL2Os=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=grlGIRijOHB5isxs6isJbYPE1uBfjbew6RTrkMRRdBxh/sOHUSYV1vnXoJYzrbHaD 67JvMj1PoLrJ/Uaztpe2xcxqJmEw4aMLobYULs9RQhSLRxm3xAKNNf0eUA4RXCyDIB Zz/IaZDgFb69kRMRWkfQYnZDhMuppJ9Mj2u/HkNw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Carolina Jubran , Shahar Shitrit , Tariq Toukan , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.1 420/982] net/mlx5e: Fix use-after-free race in sample_restore_put() Date: Wed, 30 Sep 2026 17:19:16 +0200 Message-ID: <20260930152425.824471280@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152416.775402466@linuxfoundation.org> References: <20260930152416.775402466@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.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Carolina Jubran [ Upstream commit af3aef0245abbab5e9f6302e7a7d6407187afb71 ] Concurrent teardown of TC sample rules sharing the same restore context may re-read restore->count after dropping restore_lock. At that point another thread may already have completed cleanup and freed the restore object. Use the result of the refcount decrement while holding restore_lock to determine whether cleanup is needed. Fixes: 36a3196256bf ("net/mlx5e: TC, Add sampler restore handle API") Signed-off-by: Carolina Jubran Reviewed-by: Shahar Shitrit Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260902193341.3668809-1-tariqt@nvidia.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c index c57b097275241..705455472d96a 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c @@ -311,12 +311,15 @@ sample_restore_get(struct mlx5e_tc_psample *tc_psample, u32 obj_id, static void sample_restore_put(struct mlx5e_tc_psample *tc_psample, struct mlx5e_sample_restore *restore) { + bool last; + mutex_lock(&tc_psample->restore_lock); - if (--restore->count == 0) + last = --restore->count == 0; + if (last) hash_del(&restore->hlist); mutex_unlock(&tc_psample->restore_lock); - if (!restore->count) { + if (last) { mlx5_del_flow_rules(restore->rule); mlx5_modify_header_dealloc(tc_psample->esw->dev, restore->modify_hdr); kfree(restore); -- 2.53.0