From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DFC4D606A322 for ; Sat, 5 Dec 2026 13:01:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=DFx56UY4; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Q6a2pUMn DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version: Content-Transfer-Encoding:Content-Type:References:In-Reply-To:Message-ID:Date :Cc:To:From:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=Pe0jet8ZYewS/qk3+X1o/UH/DQSVBBu/HtOz28ma9Tk=; b=DFx56UY4/UWGtq+WiVV2XgNfJS +LrH4N4jyIu7lrZ0DekTkx/ia7Inzc4CFwTkHP1CorZivMk/km8lGB59CYrnMBFDj1B9pnkmhh7sL T4LkJpvBSnUGpKp8saOjVLSvUlR1jqcaWLOwn95zFesZDezKwWfLVXtvJUT6ZEWZQMkoE4cbvKcQQ AP74fUB8E4FuiFJyU+1RYiBpB7luhDY2iVI5f9HITkKdBp+KZKPFl9YmUR3sikAp21rbnmhlIQlup n7S/+YCY98Q0O4cr6OLFNAOmbZtgpQDwIElTlNViER8kdQr4fBqcBsUmOtZoj0qTr0ykuULQ+MFia VYgLOJgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZpOd-00000002S95-1jDE; Sat, 05 Dec 2026 13:01:47 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZpOc-00000002S8x-1QGa for linux-arm-kernel@lists.infradead.org; Sat, 05 Dec 2026 13:01:46 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 63FA360CF7; Sat, 5 Dec 2026 13:01:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C57C1F00A07; Sat, 5 Dec 2026 13:01:44 +0000 (UTC) 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== Subject: Re: [PATCH net-next] net: sparx5/lan969x: hold mact_lock while using a MAC table entry From: netdev-bot+sashiko@kernel.org To: daniel.machon@microchip.com 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 Date: Sat, 05 Dec 2026 13:01:44 +0000 Message-ID: <179647570400.3146.1153202833157638420@kernel.org> In-Reply-To: <20261204-sparx5-mact-entry-lock-v1-1-2a438292ba56@microchip.com> References: <20261204-sparx5-mact-entry-lock-v1-1-2a438292ba56@microchip.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Archived-By: MIME-Version: 1.0 X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-6.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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