From: netdev-bot+sashiko@kernel.org
To: julius@bairaktaris.de
Cc: andrew@lunn.ch, olteanv@gmail.com, razor@blackwall.org,
idosch@nvidia.com, netdev@vger.kernel.org,
bridge@lists.linux.dev, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org
Subject: Re: [PATCH net-next] net: dsa: report a deleted FDB entry as no longer offloaded
Date: Mon, 23 Nov 2026 17:44:59 +0000 [thread overview]
Message-ID: <179545589967.3135.15910184280641420924@kernel.org> (raw)
In-Reply-To: <20261122174434.975426-1-julius@bairaktaris.de>
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 3
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).
- [High] Use-after-free of a foreign bridge port's net_device in the new
deletion report.
- [Low] The commit message describes a user-visible defect: 'bridge fdb
show' keeps the offload flag, and 'bridge fdb flush ... offloaded'…
- [Low] The new offloaded=false report is a delayed, per-port message
meaning 'DSA's copy of (addr, vid) towards orig_dev is gone'.
- [Low] The new DEL path reports offloaded=false whenever the deletion
returns 0, but for refcounted entries 0 does not mean the entry left…
--
net: dsa: report a deleted FDB entry as no longer offloaded
After a successful FDB deletion requested by the bridge,
dsa_user_switchdev_event_work() now reports SWITCHDEV_FDB_OFFLOADED with
offloaded=false. The bridge then clears BR_FDB_OFFLOADED on entries the
switch no longer holds. Deletions replayed for a single port that leaves a
bridge or LAG (ctx != NULL) are not reported.
> The addition has been reported since commit c9eb3e0f8701 ("net: dsa: Add
> support for learning FDB through notification"); a deletion never was.
[ ... ]
> Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
[Severity: Low]
This isn't a bug, but should this have a Fixes: tag?
The message names the origin commit in the text. It also describes a
defect users can see in "bridge fdb show" and
"bridge fdb flush ... offloaded". The prerequisite is sent as
[PATCH net]. However, the only trailer is Signed-off-by.
> diff --git a/net/dsa/user.c b/net/dsa/user.c
> index 041f9060c8ef0..fdeb1c68c2f4b 100644
> --- a/net/dsa/user.c
> +++ b/net/dsa/user.c
[ ... ]
> @@ -3628,13 +3629,14 @@ static int dsa_user_netdevice_event(struct notifier_block *nb,
> }
>
> static void
> -dsa_fdb_offload_notify(struct dsa_switchdev_event_work *switchdev_work)
> +dsa_fdb_offload_notify(struct dsa_switchdev_event_work *switchdev_work,
> + bool offloaded)
> {
> struct switchdev_notifier_fdb_info info = {};
>
> info.addr = switchdev_work->addr;
> info.vid = switchdev_work->vid;
> - info.offloaded = true;
> + info.offloaded = offloaded;
> call_switchdev_notifiers(SWITCHDEV_FDB_OFFLOADED,
> switchdev_work->orig_dev, &info.info, NULL);
> }
[ ... ]
> @@ -3681,8 +3683,13 @@ static void dsa_user_switchdev_event_work(struct work_struct *work)
> dev_err(ds->dev,
> "port %d failed to delete %pM vid %d from fdb: %d\n",
> dp->index, addr, vid, err);
> + break;
> }
> -
> + /* A deletion replayed for this port alone, as it leaves the
> + * bridge or a LAG, can leave the entry held for other ports
> + */
> + if (!switchdev_work->replayed)
> + dsa_fdb_offload_notify(switchdev_work, false);
[Severity: High]
Can this call use a freed net_device?
Before this patch, the DEL branch only used switchdev_work->dev.
dsa_flush_workqueue() in dsa_port_pre_bridge_leave() keeps that device
alive.
The DEL branch now calls dsa_fdb_offload_notify(), which passes
switchdev_work->orig_dev to call_switchdev_notifiers().
dsa_user_fdb_event() stores orig_dev without netdev_hold() or dev_hold():
switchdev_work->orig_dev = orig_dev;
orig_dev can be a foreign bridge port such as a veth. Suppose that port
has FDB entries DSA offloaded, either static or learned with
ds->assisted_learning_on_cpu_port, and it is then deleted:
ip link del veth0
br_del_if()
del_nbp()
br_fdb_cleanup_by_dst()
br_switchdev_fdb_notify() /* SWITCHDEV_FDB_DEL_TO_DEVICE */
__switchdev_handle_fdb_event_to_device()
dsa_user_fdb_event() /* ctx == NULL, replayed == false */
dsa_schedule_work()
netdev_upper_dev_unlink()
Nothing flushes dsa_owq when a foreign device unregisters.
dsa_user_netdevice_event() has no NETDEV_UNREGISTER case, and
dsa_flush_workqueue() only runs when DSA ports or LAGs leave the bridge.
So netdev_run_todo() and free_netdev() can free veth0 while these works
are still queued, for example behind slow MDIO or SPI port_fdb_del calls.
The work then runs:
dsa_user_switchdev_event_work()
dsa_fdb_offload_notify(switchdev_work, false)
call_switchdev_notifiers(SWITCHDEV_FDB_OFFLOADED, orig_dev, ...)
br_switchdev_event()
p = br_port_get_rtnl_rcu(dev); /* dev already freed */
The existing ADD report has the same lifetime gap, but only through a
narrow race with unregistration. Here, the teardown of orig_dev is what
generates the DEL report.
The note below the '---' line says this depends on "net: dsa: hold the
device a queued FDB event is reported to". That patch is not in this
tree, and git am drops the note.
Could the two go in as a series, or could the dependency be recorded in
the commit message itself? Otherwise this patch could be applied or
backported without it.
[Severity: Low]
Does a return value of 0 here mean the entry has left the switch?
Host addresses on CPU and DSA ports are refcounted, and so are LAG
entries. dsa_port_do_fdb_del() returns 0 when only the refcount drops:
net/dsa/switch.c:dsa_port_do_fdb_del() {
...
if (!refcount_dec_and_test(&a->refcount)) {
trace_dsa_fdb_del_drop(dp, addr, vid, &db, &a->refcount);
goto out;
}
err = ds->ops->port_fdb_del(ds, port, addr, vid, db);
...
if (err) {
refcount_set(&a->refcount, 1);
goto out;
}
...
}
Take a host address X added for DSA user ports A and B, giving a refcount
of 2 on the CPU port:
- A's DEL drops the refcount to 1 and reports false.
- B's DEL then fails in port_fdb_del(). The refcount is restored to 1 and
nothing is reported.
The last report the bridge received is false, but the switch still holds
X.
The same thing can happen if the GFP_ATOMIC allocation in
dsa_user_fdb_event() fails for B. __switchdev_handle_fdb_event_to_device()
stops at the first error other than -EOPNOTSUPP:
if (err && err != -EOPNOTSUPP)
return err;
Doesn't that contradict this line in the commit message: "the last one
for an entry gives the state the switch was left in"?
[Severity: Low]
Can this report reach a different bridge than the one the deletion was
for?
The report goes to the orig_dev captured at queue time. However,
br_switchdev_event() finds the bridge from orig_dev's current bridge port
when the work runs. br_fdb_offloaded_set() also ignores p and matches
only addr and vid:
net/bridge/br_fdb.c:br_fdb_offloaded_set() {
...
fdb = br_fdb_find(br, addr, vid);
if (fdb && offloaded != test_bit(BR_FDB_OFFLOADED, &fdb->flags))
change_bit(BR_FDB_OFFLOADED, &fdb->flags);
...
}
Suppose foreign port V leaves bridge B1, so del_nbp() queues DSA DEL
works with orig_dev = V. V then joins bridge B2 before dsa_owq runs those
works.
Would the report then clear BR_FDB_OFFLOADED on B2's (addr, vid) entry?
One example is V's own local address added again in B2, even if another
switchdev driver in B2 offloaded it.
The commit message covers the same-bridge case ("a deletion still queued
here can clear the flag that driver set on an entry re-created on one of
its ports"). It does not cover this cross-bridge case.
br_fdb_cleanup_by_dst() keeps ext-learned entries only while
BR_FDB_OFFLOADED is clear:
if (test_bit(BR_FDB_STATIC, &f->flags) ||
(test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &f->flags) &&
!test_bit(BR_FDB_OFFLOADED, &f->flags))) {
So a wrongly cleared flag in either case also changes which entries those
flushes delete.
> break;
> }
>
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122174434.975426-1-julius%40bairaktaris.de
prev parent reply other threads:[~2026-11-23 17:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 17:44 [PATCH net-next] net: dsa: report a deleted FDB entry as no longer offloaded Julius Bairaktaris
2026-11-23 17:44 ` 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=179545589967.3135.15910184280641420924@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew@lunn.ch \
--cc=bridge@lists.linux.dev \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=julius@bairaktaris.de \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.org \
/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