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 4B8AA4F93CC; Wed, 30 Sep 2026 16:19:49 +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=1790785194; cv=none; b=MiEJwuNVGH2aI34H779dUeTKcjHrFhle1OY5cDcPzSvD4q+jmUPNw3hTe6p83RtpK3o3ZjG8JcV+FhbMw/KLoDgDdE/duK++F1DBvBDOKjYuJPkmju+vk8ThJe5OGj2Sg+L40Jp7nJuOow4rUEYiP3U4yQ6ELwX/Y8wg/Btd5sk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790785194; c=relaxed/simple; bh=9rgVWNdx17wo36JlJpBBtBLqVseYQHHUc3UIjviFr3Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y4T+t9xx1b1KKqjAyKXdlm3r1US0uZwnjxKjcmwvLkiY9hdB7gtznqIj7BC6kj1zR+syIWjaRhuHRnfLwOLOpkGcZ8p8UjKPV0EWnrGdj8LvSJVI63tJU9dnwRu24iYMp3qIwUBn6XojKLPQQ/q1fV60SQq8FWSY+ktb0+6OM7E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=2C643TPa; 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="2C643TPa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B29861F00893; Wed, 30 Sep 2026 16:19:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790785189; bh=Q2Ry5x9VNIpigctvVuPVzMhpU6otNRETdBz6EY35LgE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=2C643TPap+zcJ3VArWG1MNGFvnIqnu1UD98G+Gl7vZQl2YGrDs44bOYV7P0sGlXDx Dks10AmmUEONZ+5/XbSlwzhYqmupoQawf99m/Z1+VEHK+1UjYtngwoh6KN7ck89Iq+ 4jx2QIZvnYYziji6a/3Un6KAdBHy0fd5XNL4eQHU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yael Chemla , Dragos Tatulea , Tariq Toukan , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.1 421/982] net/mlx5: E-Switch: fix use-after-free in mlx5_eswitch_termtbl_put Date: Wed, 30 Sep 2026 17:19:17 +0200 Message-ID: <20260930152425.847450041@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: Yael Chemla [ Upstream commit 7ee07f601f8f507c9faf25c68a49396ab8950596 ] In mlx5_eswitch_termtbl_put(), the zero-ref cleanup check reads tt->ref_count after termtbl_mutex has been released. Two concurrent callers on the same mlx5_termtbl_handle race: one decrements ref_count to zero, removes the hash entry, and calls kfree(tt) while the other has already dropped the mutex and is about to evaluate if (!tt->ref_count), producing a use-after-free. Fix this by capturing the result of the decrement into a stack-local last variable before dropping the mutex. The cleanup decision is now made entirely under termtbl_mutex, and tt is not touched after kfree. Fixes: 10caabdaad5a ("net/mlx5e: Use termination table for VLAN push actions") Signed-off-by: Yael Chemla Reviewed-by: Dragos Tatulea Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260902193514.3668880-1-tariqt@nvidia.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- .../ethernet/mellanox/mlx5/core/eswitch_offloads_termtbl.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads_termtbl.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads_termtbl.c index edd9102583144..cc59ad6d161ab 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads_termtbl.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads_termtbl.c @@ -163,12 +163,15 @@ void mlx5_eswitch_termtbl_put(struct mlx5_eswitch *esw, struct mlx5_termtbl_handle *tt) { + bool last; + mutex_lock(&esw->offloads.termtbl_mutex); - if (--tt->ref_count == 0) + last = (--tt->ref_count == 0); + if (last) hash_del(&tt->termtbl_hlist); mutex_unlock(&esw->offloads.termtbl_mutex); - if (!tt->ref_count) { + if (last) { mlx5_del_flow_rules(tt->rule); mlx5_destroy_flow_table(tt->termtbl); kfree(tt); -- 2.53.0