Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1874989lql; Wed, 13 Mar 2024 10:26:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV+8PS8mkorUZGyMhGO7FdhJ2spOz5BzWZtpcyvDVq2d2kGrc8kucmQm0aOPmVeajrhBw+Q5xzk3RW6/m3ofL9YS2DjvgKlRoe/B7E/tQ== X-Google-Smtp-Source: AGHT+IEPiyVCHkLfI+iLttVYygj4dHX5vJ35/3BP/jQDntMbALcQwNscYH2Ce4qDoGKggwrV6lfN X-Received: by 2002:a17:90a:f3cf:b0:29b:eb6a:4b02 with SMTP id ha15-20020a17090af3cf00b0029beb6a4b02mr3910848pjb.22.1710350807815; Wed, 13 Mar 2024 10:26:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710350807; cv=pass; d=google.com; s=arc-20160816; b=anilRqOospNRmhZOQOi1E9Bo+yWIXYwzFOBaNGN9e5jgYFtEF8qtPR6K+qUgljCNGo hyizqJOhWMoiAyCoD+q/o7aiuNbM33XvUOar9WCCzBdK1aHHQbk24AZ2+t7ae4CVZSNB g4ZVEVX/F4ku1YG8wmKVALP5mQt0FUr+iIoF3D859Pzig7Yllw+2d/Q44n8HPRTPzgTf UWizTvUizkIv9TPP57WDR3ne5XnOKOhvq8nV+PX4Vw8M6ugxj61AYqpicrH+C+TVVOWG /2UhLUG/NqvHpQP1oVCC91a2Pc0pLp4drxSU8dPCcVsZjaPZCTyAxf2WNbzi6tALYKoY hhKA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=1K58LEIxvUe2RjNGN6QgYNuqSAXgRZeH/uFuHffRX9w=; fh=2Q/U9VJ17ssjm+8gudEYNXVjsAxcHSELcc38Oe5VV04=; b=dGTsm3ZJo//BhhA0CzqbRqACwML1utB1bKQoZrdwPMyDY3a8/sQsjHodsy+syb6k7a 6o+wQwCxNQuTeRTmL0f6VSWalg+ufnNW3ZZy7/oY5uIP+2JCYwG31v7NLfI7AtiTulhD RE1VhRPL+TT0TEwc5XQYIQKo8Q9zwl03gs2Ya33r5hpxFTvTWEkAduMIEGg5syaPAo6G BgKn3SKCtveapcecT6Zte0nCnwUxZ/vX6I8liUadwqmbEYV8+kMGaI2/+wHll+1Rx7/q xR8OSF4iuBRT1dH03D9wdWm17k8Ym6aAgQN/KsemaWrJAPGerZKPx3yFQiDm4xbMPeIJ GqGg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DpJd3Ut1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101948-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101948-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id bv5-20020a17090af18500b0029c5b1bf1c2si1785512pjb.140.2024.03.13.10.26.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:26:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101948-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DpJd3Ut1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101948-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101948-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 932B9281BBC for ; Wed, 13 Mar 2024 17:23:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1CD6F62A14; Wed, 13 Mar 2024 16:42:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DpJd3Ut1" 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 451A81369A3; Wed, 13 Mar 2024 16:42: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=1710348156; cv=none; b=oIrzD13+206j+spYwVFQ+XFkIyxEfu1zolF0iiRonjF52nwi2S6X00j67RlvXYnoLiZ66GhNYyj6/mncevF1EMqsCxsqHaz+++JvsAUhJyXNU1U555UUZcKYXvi6s+DGDVWn75MtJ5hGi0Zw8l70T+eXtgwz8Pu0iYDinz4lHzE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710348156; c=relaxed/simple; bh=bxywz7gfC5Zr9syRS/KzdmYrKoUf25nSuiCn3skB54w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u7QL9PNk2esBedNCPRdWxdoG7BM4Kh5yUKHr4VFkkIDZAGS5VnEjeg3mp5AqTIkZJAngf770I6+vxlo7KWxcNvntL2UOSPO0vJJuliCpqQpEh/JmeeFwXPH5OsmdTZ/ipSCyn97GqCY9DZPdKheqQW73b5oNNObQgHxIhvLhCGw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DpJd3Ut1; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E8BBC43141; Wed, 13 Mar 2024 16:42:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710348156; bh=bxywz7gfC5Zr9syRS/KzdmYrKoUf25nSuiCn3skB54w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DpJd3Ut1mNg9pdAZvTIPCGNWXo6Gh9Pc2+j3qthgZgmKRlPdFViSaGiT4P5IyBzAe LqPr5w4FxfpZn+GmAgiTXej1LQpl2CNS10eaf7GVgGp3eyrkADXnvkNGMQ9PqDxMLO b4bjAdsnJVaPhizAE27dTTLToMrO3jfohU+Xn7dSp/EuOQpdBe3JcvrTJ/Gcjm6Hz9 +tG4uCflEvnyeOIfn82GhdT1cUwG8HzFL6kwRuLcaWz/7jrC7+OKEamBlpHcdUuyL2 UGSx5Nr04//H4LJYskq8SP0czEzBp6Y93OTT8OfpSYQ9XR1RArFYvKhVBaaJIFmvR9 cx/8n9WM4EXXQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Horatiu Vultur , Simon Horman , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 08/76] net: sparx5: Fix use after free inside sparx5_del_mact_entry Date: Wed, 13 Mar 2024 12:41:15 -0400 Message-ID: <20240313164223.615640-9-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240313164223.615640-1-sashal@kernel.org> References: <20240313164223.615640-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.15.152-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.15.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.15.152-rc1 X-KernelTest-Deadline: 2024-03-15T16:42+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Horatiu Vultur [ Upstream commit 89d72d4125e94aa3c2140fedd97ce07ba9e37674 ] Based on the static analyzis of the code it looks like when an entry from the MAC table was removed, the entry was still used after being freed. More precise the vid of the mac_entry was used after calling devm_kfree on the mac_entry. The fix consists in first using the vid of the mac_entry to delete the entry from the HW and after that to free it. Fixes: b37a1bae742f ("net: sparx5: add mactable support") Signed-off-by: Horatiu Vultur Reviewed-by: Simon Horman Link: https://lore.kernel.org/r/20240301080608.3053468-1-horatiu.vultur@microchip.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c b/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c index 9a8e4f201eb1f..6ba93fa984f26 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c @@ -344,10 +344,10 @@ int sparx5_del_mact_entry(struct sparx5 *sparx5, list) { if ((vid == 0 || mact_entry->vid == vid) && ether_addr_equal(addr, mact_entry->mac)) { + sparx5_mact_forget(sparx5, addr, mact_entry->vid); + list_del(&mact_entry->list); devm_kfree(sparx5->dev, mact_entry); - - sparx5_mact_forget(sparx5, addr, mact_entry->vid); } } mutex_unlock(&sparx5->mact_lock); -- 2.43.0