From: netdev-bot+sashiko@kernel.org
To: mmyangfl@gmail.com
Cc: netdev@vger.kernel.org, andrew@lunn.ch, olteanv@gmail.com,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com
Subject: Re: [PATCH net-next v2 5/5] net: dsa: motorcomm: Reject bridge flags that break redirect rules
Date: Mon, 30 Nov 2026 12:25:57 +0000 [thread overview]
Message-ID: <179604155795.3146.3013639565028372543@kernel.org> (raw)
In-Reply-To: <20261129115556.1669188-6-mmyangfl@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · 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).
- [High] The patch adds a check in yt921x_dsa_port_pre_bridge_flags()
(drivers/net/dsa/motorcomm/chip.c) to reject bridge flag changes that…
--
net: dsa: motorcomm: Reject bridge flag changes that break redirect rules
This patch adds per-destination counters, acl_dst_cnts[], for hardware-only
(non sw_assisted) redirect ACL rules. yt921x_dsa_port_pre_bridge_flags()
now uses them to reject turning hairpin mode off, or isolating a port, when
the change would block an installed redirect rule.
> diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
> index 7282bc0693ebb..40d0334f3d74c 100644
> --- a/drivers/net/dsa/motorcomm/chip.c
> +++ b/drivers/net/dsa/motorcomm/chip.c
> @@ -1465,9 +1465,44 @@ yt921x_dsa_port_pre_bridge_flags(struct dsa_switch *ds, int port,
> struct switchdev_brport_flags flags,
> struct netlink_ext_ack *extack)
> {
> + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);
> + struct yt921x_port *pp = &priv->ports[port];
> +
> if (flags.mask & ~(BR_HAIRPIN_MODE | BR_LEARNING | BR_FLOOD |
> BR_MCAST_FLOOD | BR_ISOLATED))
> return -EINVAL;
> +
> + if ((flags.mask & BR_HAIRPIN_MODE) && !(flags.val & BR_HAIRPIN_MODE) &&
> + pp->acl_dst_cnts[port]) {
> + NL_SET_ERR_MSG_MOD(extack,
> + "Cannot disable hairpin mode while there are hairpin redirect rules installed");
> + return -EINVAL;
> + }
> +
> + if ((flags.mask & BR_ISOLATED) && (flags.val & BR_ISOLATED)) {
> + struct dsa_port *dp = dsa_to_port(ds, port);
> + unsigned long ports_mask;
> + struct net_device *bdev;
> + unsigned int i;
> +
> + bdev = dsa_port_bridge_dev_get(dp);
> + if (!bdev)
> + return 0;
> +
> + ports_mask = dsa_bridge_ports(ds, bdev);
> + for_each_set_bit(i, &ports_mask, YT921X_PORT_NUM) {
> + if (i == port || !priv->ports[i].isolated)
> + continue;
[Severity: High]
Can this check be bypassed, because the state it reads hasn't been
committed yet?
pp->isolated, pp->hairpin and pp->isolation_mask are only updated in
yt921x_bridge_flags():
drivers/net/dsa/motorcomm/chip.c:yt921x_bridge_flags() {
...
if (flags.mask & BR_HAIRPIN_MODE) {
pp->hairpin = flags.val & BR_HAIRPIN_MODE;
...
if (flags.mask & BR_ISOLATED) {
pp->isolated = flags.val & BR_ISOLATED;
...
res = yt921x_bridge(priv, ports_mask);
...
}
br_switchdev_set_port_flag() sends PRE_BRIDGE_FLAGS synchronously. It then
queues BRIDGE_FLAGS as deferred:
net/bridge/br_switchdev.c:br_switchdev_set_port_flag() {
...
attr.id = SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS;
attr.flags = SWITCHDEV_F_DEFER;
err = switchdev_port_attr_set(p->dev, &attr, extack);
...
}
switchdev_deferred_process_work() takes rtnl_lock() again later, from a
workqueue. So other RTM_SETLINK or tc requests can run between this check
and the commit, and they still see the old driver state.
With A and B in the same bridge and a skip_sw redirect A->B installed
(ports[A].acl_dst_cnts[B] == 1):
bridge link set dev A isolated on
-> pre_bridge_flags(A) passes, B is not isolated yet
-> BRIDGE_FLAGS(A) queued
bridge link set dev B isolated on (e.g. next message in the same batch)
-> pre_bridge_flags(B) passes, ports[A].isolated is still false,
so the !priv->ports[i].isolated test skips A
deferred work runs both commits
-> yt921x_bridge() puts B into A's isolation_mask
The tc side has the same window. If B is already isolated,
pre_bridge_flags(A, isolated on) passes while no rules exist. A skip_sw
"mirred egress redirect dev B" on A is then checked in
yt921x_acl_rule_ext_parse_flow_action() against the old mask:
if (pp->isolation_mask & BIT(to_dp->index)) {
if (cls->common.skip_sw) {
So the rule is accepted as hardware-only, and the deferred commit then
isolates A.
The same thing can happen with hairpin. Turning hairpin off on A passes
while acl_dst_cnts[A] is 0. A skip_sw A->A redirect is then accepted
because pp->hairpin is still set, and the deferred commit clears it.
In all three cases nothing repairs the rule afterwards, because
yt921x_acl_recompute() skips non sw_assisted rules:
if (!aclrule || !aclrule->sw_assisted)
continue;
So the hardware redirect is silently blocked, which is the case the commit
message says this patch prevents.
Would it work to make the pre-check and the tc parse check use the same
committed or pending state? One option is to read the bridge port flags,
which br_setport() stores right after the pre-check succeeds. Another is to
record the pending isolated/hairpin state in the driver during
pre_bridge_flags.
> +
> + if (pp->acl_dst_cnts[i] ||
> + priv->ports[i].acl_dst_cnts[port]) {
> + NL_SET_ERR_MSG_MOD(extack,
> + "Cannot isolate port while there are redirect rules installed");
> + return -EINVAL;
> + }
> + }
> + }
> +
> return 0;
> }
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129115556.1669188-1-mmyangfl%40gmail.com
prev parent reply other threads:[~2026-11-30 12:25 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 11:55 [PATCH net-next v2 0/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
2026-11-29 11:55 ` [PATCH net-next v2 1/5] net: dsa: motorcomm: Remove local cpu_ports_mask David Yang
2026-11-29 11:55 ` [PATCH net-next v2 2/5] net: dsa: motorcomm: Cache port isolation masks David Yang
2026-11-30 12:25 ` netdev-bot+sashiko
2026-11-29 11:55 ` [PATCH net-next v2 3/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
2026-11-30 12:25 ` netdev-bot+sashiko
2026-11-29 11:55 ` [PATCH net-next v2 4/5] net: dsa: motorcomm: Recompute redirect rules on bridge changes David Yang
2026-11-30 12:25 ` netdev-bot+sashiko
2026-11-29 11:55 ` [PATCH net-next v2 5/5] net: dsa: motorcomm: Reject bridge flags that break redirect rules David Yang
2026-11-30 12:25 ` 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=179604155795.3146.3013639565028372543@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=mmyangfl@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--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