From: Simon Horman <simon.horman@corigine.com>
To: Vladimir Oltean <vladimir.oltean@nxp.com>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Andrew Lunn <andrew@lunn.ch>,
Florian Fainelli <f.fainelli@gmail.com>
Subject: Re: [PATCH net-next] net: dsa: fix db type confusion in host fdb/mdb add/del
Date: Thu, 30 Mar 2023 15:51:30 +0200 [thread overview]
Message-ID: <ZCWT4tK6aNBshFcl@corigine.com> (raw)
In-Reply-To: <20230329133819.697642-1-vladimir.oltean@nxp.com>
On Wed, Mar 29, 2023 at 04:38:19PM +0300, Vladimir Oltean wrote:
> We have the following code paths:
>
> Host FDB (unicast RX filtering):
>
> dsa_port_standalone_host_fdb_add() dsa_port_bridge_host_fdb_add()
> | |
> +--------------+ +------------+
> | |
> v v
> dsa_port_host_fdb_add()
>
> dsa_port_standalone_host_fdb_del() dsa_port_bridge_host_fdb_del()
> | |
> +--------------+ +------------+
> | |
> v v
> dsa_port_host_fdb_del()
>
> Host MDB (multicast RX filtering):
>
> dsa_port_standalone_host_mdb_add() dsa_port_bridge_host_mdb_add()
> | |
> +--------------+ +------------+
> | |
> v v
> dsa_port_host_mdb_add()
>
> dsa_port_standalone_host_mdb_del() dsa_port_bridge_host_mdb_del()
> | |
> +--------------+ +------------+
> | |
> v v
> dsa_port_host_mdb_del()
>
> The logic added by commit 5e8a1e03aa4d ("net: dsa: install secondary
> unicast and multicast addresses as host FDB/MDB") zeroes out
> db.bridge.num if the switch doesn't support ds->fdb_isolation
> (the majority doesn't). This is done for a reason explained in commit
> c26933639b54 ("net: dsa: request drivers to perform FDB isolation").
>
> Taking a single code path as example - dsa_port_host_fdb_add() - the
> others are similar - the problem is that this function handles:
> - DSA_DB_PORT databases, when called from
> dsa_port_standalone_host_fdb_add()
> - DSA_DB_BRIDGE databases, when called from
> dsa_port_bridge_host_fdb_add()
>
> So, if dsa_port_host_fdb_add() were to make any change on the
> "bridge.num" attribute of the database, this would only be correct for a
> DSA_DB_BRIDGE, and a type confusion for a DSA_DB_PORT bridge.
>
> However, this bug is without consequences, for 2 reasons:
>
> - dsa_port_standalone_host_fdb_add() is only called from code which is
> (in)directly guarded by dsa_switch_supports_uc_filtering(ds), and that
> function only returns true if ds->fdb_isolation is set. So, the code
> only executed for DSA_DB_BRIDGE databases.
>
> - Even if the code was not dead for DSA_DB_PORT, we have the following
> memory layout:
>
> struct dsa_bridge {
> struct net_device *dev;
> unsigned int num;
> bool tx_fwd_offload;
> refcount_t refcount;
> };
>
> struct dsa_db {
> enum dsa_db_type type;
>
> union {
> const struct dsa_port *dp; // DSA_DB_PORT
> struct dsa_lag lag;
> struct dsa_bridge bridge; // DSA_DB_BRIDGE
> };
> };
>
> So, the zeroization of dsa_db :: bridge :: num on a dsa_db structure of
> type DSA_DB_PORT would access memory which is unused, because we only
> use dsa_db :: dp for DSA_DB_PORT, and this is mapped at the same address
> with dsa_db :: dev for DSA_DB_BRIDGE, thanks to the union definition.
>
> It is correct to fix up dsa_db :: bridge :: num only from code paths
> that come from the bridge / switchdev, so move these there.
>
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
next prev parent reply other threads:[~2023-03-30 13:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-29 13:38 [PATCH net-next] net: dsa: fix db type confusion in host fdb/mdb add/del Vladimir Oltean
2023-03-30 13:51 ` Simon Horman [this message]
2023-03-30 18:19 ` Florian Fainelli
2023-03-31 6:30 ` patchwork-bot+netdevbpf
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=ZCWT4tK6aNBshFcl@corigine.com \
--to=simon.horman@corigine.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=vladimir.oltean@nxp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.