Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1845439lql; Wed, 13 Mar 2024 09:39:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWiZhIWWHJb6jv4YiBGw1HR+w5rM4gUoBFmNNzHmxGX9o7iSeOVXiRY9zyMKh7REOVBKrNr4/HKgMkXpfKClr4yyCORNYp2bxS7EX1PNA== X-Google-Smtp-Source: AGHT+IHcedz7Jq9n0xfJGwzDbftg1Ra0a75011sjdFivgBaq5GMk2babQUjzLTofvBvw7TcxuM+5 X-Received: by 2002:a67:ec44:0:b0:473:4d73:5e1c with SMTP id z4-20020a67ec44000000b004734d735e1cmr477342vso.9.1710347939926; Wed, 13 Mar 2024 09:38:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710347939; cv=pass; d=google.com; s=arc-20160816; b=Nw41mOv99k3warwu33Zg6G1hz6RBAH2vnQj7q1XfiNRd9/dZf+JtH7w58ylovhKJ+z EH39SuMQwOtMsygzOiPjTMUa+RJCfD8tomXcO12QBXFHVMzIWsd1WpUedsKc7ahmTOd2 5Nk+y8J1flDyLVm0BNhnOiFl0X+EiuD1D1ZpGG/K/mBQ4fVXvF+xqG/2l0Skjx6/nVpU 9PMfRpo8eeiGETjtMLv8KgVg2gyN+uyuc32M+SsQtiPPQXHp4UgSqsxvygswpAQPiF9v q2H0h7Hav93+3H7UDbpXErKovBvBcoLMfafuQv1eEGouwbgONaMdAz1pQFGqaQUT5Bzc dDnA== 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=mkwLhnOIMTHdPHhi5X0niLv5HQFLJnqXdJrKMCIS4aY=; fh=2Q/U9VJ17ssjm+8gudEYNXVjsAxcHSELcc38Oe5VV04=; b=mvbYA8+RiOBOfN5PNlDi0IXPyWZgCwBi+9M/C8+QLDPhHNzgnG4O4gIXWawvdw+NZw UtdzGIxSFTBbrA6u/dimvAQoqEXCpXv1A+B1Of8+6PcLmScfmadz+EksSzhMBRVnL9Yx hfM6rI2ocMYjRfVdCQC14TAuOSodPHjTwtiXokBPysOu5zwJKaJHGOotMF3S1JnNpzCw tmhmHik1ZUJJ0HMP76dTWMjMS9sEvUGaQHeHf7Vw7zx0AGjReaf6AsMPqd96conn0q8p 2Bx4rl+zWZBgIFrOSI1EmYxbMY7xgJ4EYzyscQwgobAsvAxXVJ7ICfn0+Svb0XT11ghF mR9A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="m/IbJxUf"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101766-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101766-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id on6-20020a056214448600b0068fe7f88fa3si10230014qvb.499.2024.03.13.09.38.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 09:38:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101766-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="m/IbJxUf"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101766-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101766-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A026D1C21ACD for ; Wed, 13 Mar 2024 16:38:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF28560B87; Wed, 13 Mar 2024 16:33:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="m/IbJxUf" 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 D83C160889; Wed, 13 Mar 2024 16:33:11 +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=1710347591; cv=none; b=QjWfDjd1Kays0AWfea4RdfgpuwKH+zqsYQ6q+vcxs5bft1aoF6Q0TuM1wLFmd0Al4CNPg0vDaTcxfhR0DczQvAAMSa33+MDlPwekuWiScT+vBgH1AUyZyIr47r6YzLVJMc1v//v9wIlFo22P10pWKEXMDUVUxE5XVK/lE/y6pzQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710347591; c=relaxed/simple; bh=BPbJntuskVES4ughBqn58IDptAR3zQxTerFw4OXbovw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OgP3o1JadReuHb1Tg9wG506H8QLf/w/PC35qqbKNxUJuFyp5OfcOVPGyJwHCKZKNC6y5lP2HK84ekg8lhniMLGa+pIo1qr6lDFFwRrPLm7cwYBMqb2O6YvDG6en4wY7hcuNhd2FJBUqZaympx4p+NLrnZHd9umwuW/1Bo/JoNG8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m/IbJxUf; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFF56C43394; Wed, 13 Mar 2024 16:33:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710347591; bh=BPbJntuskVES4ughBqn58IDptAR3zQxTerFw4OXbovw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m/IbJxUfQ3Q+5opwuJgtd6grMc/7OLTyRDvCIvvq6W5HceBXy2AQn1a1MngBYrMxZ kKBWgvV+q54cXJG3aAXbLy0IPe/xzuqqGI8QGX0ZoNRFnAC5sX0lGbPYX28SgrD48O WDcPFoIj4HhuLozT+dtNR5Hg45/xX8wW4yo8yc0XLmSlVP8qR0VuvJIw/5WLud5nXZ Npdslur149yS3gqGp4RxhoqD0WMleh80ZaV3rOMnPx/DkZci096Y6EfuZoYoRQC1so /RQ204Pwl3sqpJNATqEJZ1/aaz4evIbAL0Abqp9W6FLU+hgTMJJ46zYs2pNrOH1qdd VoDJg+5lMc1kQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Horatiu Vultur , Simon Horman , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.7 27/61] net: sparx5: Fix use after free inside sparx5_del_mact_entry Date: Wed, 13 Mar 2024 12:32:02 -0400 Message-ID: <20240313163236.613880-28-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240313163236.613880-1-sashal@kernel.org> References: <20240313163236.613880-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/v6.x/stable-review/patch-6.7.10-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-6.7.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 6.7.10-rc1 X-KernelTest-Deadline: 2024-03-15T16:32+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 4af285918ea2a..75868b3f548ec 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c @@ -347,10 +347,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