๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27387

Re: [PATCH net-next] net: sparx5/lan969x: hold mact_lock while using a MAC table entry

#27387
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 13:01
90 lines
11498 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 ยท High: 0 ยท Medium: 1 ยท Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The patch fixes a real memory-safety bug, but its routing
  understates that.

--

net: sparx5/lan969x: hold mact_lock while using a MAC table entry

This patch keeps mact_lock held in sparx5_add_mact_entry() and
sparx5_mact_handle_entry() for as long as they use a software MAC table
entry. find_mact_entry() no longer takes the lock itself and now asserts
that the caller holds it.

> In the first gap, the MAC table pull can reap the entry as aged,
> because MAC_ENT_LOCK is not set yet. In the second, the FDB work can
> delete it through sparx5_del_mact_entry(). For a host entry, whose port
> is a PGID, the reap also indexes sparx5->ports[] out of bounds.

[ ... ]

> This is in preparation for LAG support, which follows in a later
> series.

[ ... ]

> This does not fix a regression, so it is targeted at net-next.

[Severity: Medium]
The code change itself looks correct. Should this go to net with Fixes:
tags instead of net-next, though?

The gaps described above look like use-after-free bugs in the existing
code, but the commit message doesn't say so.

sparx5_add_mact_entry() is called from the FDB work on sparx5_owq.
sparx5_mact_pull_work() runs on sparx5->mact_queue. These are different
workqueues, so the two can run at the same time. Before this patch, the
add path could race with the reap like this:

CPU1 (FDB work)
sparx5_add_mact_entry()
    list_add_tail(&mact_entry->list, &sparx5->mact_entries);
    mutex_unlock(&sparx5->mact_lock);
    sparx5_mact_learn(...);

CPU2 (MAC table pull)
sparx5_mact_pull_work()
    /* flags == 0, neither MAC_ENT_ALIVE nor MAC_ENT_LOCK set */
    sparx5_fdb_call_notifiers(SWITCHDEV_FDB_DEL_TO_BRIDGE,
                              mact_entry->mac, mact_entry->vid,
                              sparx5->ports[mact_entry->port]->ndev,
                              true);
    list_del(&mact_entry->list);
    devm_kfree(sparx5->dev, mact_entry);

CPU1
    if (mact_entry->flags == 0) {
        mact_entry->flags |= MAC_ENT_LOCK;

The final read and write of mact_entry->flags then touch freed memory.

Host entries are added from sparx5_switchdev_bridge_fdb_event_work() with
sparx5_get_pgid(sparx5, PGID_CPU) as the port. For those, the reap also
reads past the end of sparx5->ports[] before the free.

The pull path has the same problem. sparx5_mact_handle_entry() read
mact_entry->flags & MAC_ENT_MOVED after dropping mact_lock. By then,
sparx5_del_mact_entry() in the FDB work could already have done list_del()
and devm_kfree() on that entry.

Normal FDB add and ageing activity can reach both paths. Would it make
sense to describe them as use-after-free and add tags like these, so that
stable kernels get the fix even though the LAG series also builds on it?

Fixes: b37a1bae742f ("net: sparx5: add mactable support")
Fixes: 9f01cfbf2922 ("net: sparx5: Use Switchdev fdb events for managing fdb entries")

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-sparx5-mact-entry-lock-v1-1-2a438292ba56%40microchip.com
Technical Details
Message-ID: <179647570400.3146.1153202833157638420@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377995-linux-kernel-netdev=dewy.ru
References: <20261204-sparx5-mact-entry-lock-v1-1-2a438292ba56@microchip.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377995-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next] net: sparx5/lan969x: hold mact_lock while using
 a MAC table entry
Date: Sat, 05 Dec 2026 13:01:44 +0000
Organization: Usenet Network
Message-ID: <179647570400.3146.1153202833157638420@kernel.org>
References: <20261204-sparx5-mact-entry-lock-v1-1-2a438292ba56@microchip.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3031689"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:pOAvjhWFT72QIBdpBDwB61K48SQ= sha256:doC0+oBN7VhT37aolakxy8PqCvrQAxr18Xj2Du8QXyU=
	sha1:uc7BwFBvYpqCzU8+zoHibB1BjOg= sha256:J9Nqz/AnR9RQgp0jgaM5SDKf9f/Ltr0TI8SMTRw3n1g=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 519C3117E16; Sat,  5 Dec 2026 16:02:05 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.539
X-Spam-Status: No, score=-3.539 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.14, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id gJO4a04pmHfT;
	Sat,  5 Dec 2026 16:02:01 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377995-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 731731177D1; Sat,  5 Dec 2026 16:01:50 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 8784A29556; Sat,  5 Dec 2026 13:01:46 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796475706;
	b=YVNzC8uVSkX3Q3Fp05iwM6/kfRG5A9Hq2Uo6T8s/CKxI6OpujQDCuqRJIvTfxezRaiR5
	 ZN8hP67W7u97nx16lKONEOAl3fu0mYoJbzv8Wzd5kGhrgRERRjpER0bwWykC2cvXQEHww
	 ZtUWdiU8kdyyMQUsIbSDh6ShVP3i0my42R9teC4br2cbzVWsfozk8DkHEOZHt8zDPzcEo
	 02rHgiTHD4NGaW5+EdJmhSY4WTj/sBZsxKnbr/632UZem/g6M6u0cn21JBLuaIOcpcHtj
	 GJ+C0ZLy9X8Uc6YuceBEPdydtJBUt5u8takelOg94BYs7YBbPtNGPOdHGjG48lQ8FTg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796475706;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=Pe0jet8ZYewS/qk3+X1o/UH/DQSVBBu/HtOz28ma9Tk=;
	b=yAa+Q5ShFmAAK3ifKM2xHVzKd2fG7QT8YMxRyhukOToSsZ0cgdaMW3sVVcYP0gAX0yVm
	 4hXcKbSZmCQWyNy8q5OZaPve67p0JAYE6P9UhgMc8f+wRun5jRwc3DbvwIAXQSMmEPYx8
	 z9Rg9mRpd5ui/5yGnAEjNagWVbO5nKaE7RflmMjrPfaWpit+QyZhQDqhWiclRdrEjYjgL
	 NaOK21kbtw7cNiccjVjJ9ILG/a2wvYm1eq6bCigS7AbI6v/sXYAs91rIKm6PyhyeGhTEq
	 grd7xXXACKPoJxNsuW1hbmNhbsq/QWJcWbKHZ4B/19Mtdwc6y3Wk0c64KLHo2xnVILg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Q6a2pUMn;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 6054F606A333;
	Sat,  5 Dec 2026 13:01:46 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Q6a2pUMn
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796475705;
	b=nZg0qWmFh/9/g586b3pywL09su0vn38kBYsn19sZrbbHXwGdcmbb/GWNf0O8xggunUQp
	 unmcbmbNGc78g15CkO+uYUPLQwh5mRkVoV2ZqNp29rVYZA1e36a3j0kZJRFZsMnOAEtUP
	 yq48m5H/1z3fcSF0MpB8CFzbDR+DpiRBnxICXuH2zwVx+S6g6JnokVQQI3rCsjt7utSeD
	 58spoqu0vcQ0X5MohrD/FoNsfIYw9mOCwVVeWfVcHfys/ztsZihNe6V9aeeIdbX+NRun9
	 Ya5SN6gQOezsoJ2mrZtrvxpEFeVZufzJ+FotelU2O20NTooEplKPmPixQD0T0rHHb9A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796475705;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=Pe0jet8ZYewS/qk3+X1o/UH/DQSVBBu/HtOz28ma9Tk=;
	b=knrddRn+4HIbApBGgUNz7wQD0QI55xjx/Ni907NoPMldbp5gOfmOmGvNJeRPk+bH+Kkm
	 lwkzzJQNDiS59b1R0VZYCvJl/mSaCRz3IJRAK3cg0B05TGuXrUSvl39RNO+QObMr0PXna
	 rNmAHHPeP54QVkgCGARIQcA/d+f7N/VaDp4jxMZ+8Ui2w58Ol0kZEc8m5FJWxZLRN+6G4
	 P+ikQgvoTq/vCAyFq3YBVSSNGFGl2SSUQTEqbgO7HDnzdPUUJ0PqBU/1Y0YwABNKNrvCq
	 KBhXAkPpaFVUrkeRZalpuEx5cRUW1MCcuGjgMgCWFchpEXT5d2PEkYCxHcNnVWP62Ew==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Q6a2pUMn;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CEA9606A322
	for <netdev@vger.kernel.org>; Sat,  5 Dec 2026 13:01:45 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C57C1F00A07;
	Sat,  5 Dec 2026 13:01:44 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796475705;
	bh=Pe0jet8ZYewS/qk3+X1o/UH/DQSVBBu/HtOz28ma9Tk=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=Q6a2pUMn8f2SzjMTemQnc8skrK6zGSEowdMFx1d2TA1lZsgE2v+oQ8g0AwfyKBAVq
	 JiDb/1y/Q7L4/SfZ0WGMrks2dBYbBestrhSRhb8sLroxiN42wRcOzCVnNH5Y7tWwAg
	 rKKPmMdWC79p7NZsujuUUMMF3TZch6Yw2dnOz3S6lKuGA1krwqOX4eVSjnKTPsjbL9
	 4LhOVOJyhvZRtuQmsVbZB+Uw7pE5D8VMtzto9zwOG37RjqOi5c3OXGeU+YWVC0VmQb
	 pnrbxvQO1QtzrIvW4mpTuXayU68drnhv3Gwt3jXlqnxQL6h07xnjNcjUduc8IlTp5e
	 PIpj9FvqJyidQ==
X-Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, Steen.Hegelund@microchip.com,
 UNGLinuxDriver@microchip.com, netdev@vger.kernel.org,
 linux-arm-kernel@lists.infradead.org, kees+treewide@kernel.org
X-In-Reply-To: <20261204-sparx5-mact-entry-lock-v1-1-2a438292ba56@microchip.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list