From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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 ; Sat, 5 Dec 2026 13:01:45 +0000 (UTC) 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 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-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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