[PATCH net-next] net: sparx5/lan969x: hold mact_lock while using a MAC table entry
netdev-bot+sashiko at kernel.org
netdev-bot+sashiko at kernel.org
Sat Dec 5 05:01:44 PST 2026
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
More information about the linux-arm-kernel
mailing list