Netdev List
 help / color / mirror / Atom feed
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
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	[thread overview]
Message-ID: <179647570400.3146.1153202833157638420@kernel.org> (raw)
In-Reply-To: <20261204-sparx5-mact-entry-lock-v1-1-2a438292ba56@microchip.com>

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

      parent reply	other threads:[~2026-12-05 13:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 12:35 [PATCH net-next] net: sparx5/lan969x: hold mact_lock while using a MAC table entry Daniel Machon
2026-12-04 12:37 ` netdev-bot+sinfo
2026-12-05 13:01 ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179647570400.3146.1153202833157638420@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=Steen.Hegelund@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=daniel.machon@microchip.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kees+treewide@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox