* [PATCH][next] net: dsa: sja1105: remove redundant re-assignment of pointer table
@ 2021-07-22 19:15 Colin King
2021-07-22 20:05 ` Vladimir Oltean
0 siblings, 1 reply; 3+ messages in thread
From: Colin King @ 2021-07-22 19:15 UTC (permalink / raw)
To: Vladimir Oltean, Andrew Lunn, Vivien Didelot, Florian Fainelli,
David S . Miller, Jakub Kicinski, netdev
Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
The pointer table is being re-assigned with a value that is never
read. The assignment is redundant and can be removed.
Addresses-Coverity: ("Unused value")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/net/dsa/sja1105/sja1105_main.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c
index 6618abba23b3..c65dba3111d7 100644
--- a/drivers/net/dsa/sja1105/sja1105_main.c
+++ b/drivers/net/dsa/sja1105/sja1105_main.c
@@ -2157,8 +2157,6 @@ static int sja1105_build_vlan_table(struct sja1105_private *priv)
if (!new_vlan)
return -ENOMEM;
- table = &priv->static_config.tables[BLK_IDX_VLAN_LOOKUP];
-
for (i = 0; i < VLAN_N_VID; i++)
new_vlan[i].vlanid = VLAN_N_VID;
--
2.31.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH][next] net: dsa: sja1105: remove redundant re-assignment of pointer table
2021-07-22 19:15 [PATCH][next] net: dsa: sja1105: remove redundant re-assignment of pointer table Colin King
@ 2021-07-22 20:05 ` Vladimir Oltean
2021-07-23 12:32 ` Vladimir Oltean
0 siblings, 1 reply; 3+ messages in thread
From: Vladimir Oltean @ 2021-07-22 20:05 UTC (permalink / raw)
To: Colin King
Cc: Andrew Lunn, Vivien Didelot, Florian Fainelli, David S . Miller,
Jakub Kicinski, netdev, kernel-janitors, linux-kernel
On Thu, Jul 22, 2021 at 08:15:29PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> The pointer table is being re-assigned with a value that is never
> read. The assignment is redundant and can be removed.
>
> Addresses-Coverity: ("Unused value")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
> drivers/net/dsa/sja1105/sja1105_main.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c
> index 6618abba23b3..c65dba3111d7 100644
> --- a/drivers/net/dsa/sja1105/sja1105_main.c
> +++ b/drivers/net/dsa/sja1105/sja1105_main.c
> @@ -2157,8 +2157,6 @@ static int sja1105_build_vlan_table(struct sja1105_private *priv)
> if (!new_vlan)
> return -ENOMEM;
>
> - table = &priv->static_config.tables[BLK_IDX_VLAN_LOOKUP];
> -
> for (i = 0; i < VLAN_N_VID; i++)
> new_vlan[i].vlanid = VLAN_N_VID;
>
> --
> 2.31.1
>
Oh my, what an interesting bug you uncovered.
That duplicate assignment was introduced in commit 3f01c91aab92 ("net:
dsa: sja1105: implement VLAN retagging for dsa_8021q sub-VLANs") and
used to read:
table = &priv->static_config.tables[BLK_IDX_VLAN_LOOKUP];
new_retagging = kcalloc(SJA1105_MAX_RETAGGING_COUNT,
table->ops->unpacked_entry_size, GFP_KERNEL);
In retrospect, it should have been:
table = &priv->static_config.tables[BLK_IDX_RETAGGING];
because we must allocate SJA1105_MAX_RETAGGING_COUNT elements of the
size of one VLAN retagging entry, and not of one VLAN lookup entry.
In commit 0fac6aa098ed ("net: dsa: sja1105: delete the
best_effort_vlan_filtering mode") I deleted everything that had to do
with VLAN retagging but left this behind because it didn't say RETAGGING
on it.
[BLK_IDX_VLAN_LOOKUP] = {
.unpacked_entry_size = sizeof(struct sja1105_vlan_lookup_entry),
},
[BLK_IDX_RETAGGING] = {
.unpacked_entry_size = sizeof(struct sja1105_retagging_entry),
},
and if you look at them, struct sja1105_retagging_entry has 7 u64
fields, while struct sja1105_vlan_lookup_entry has 6 elements (actually
since commit 3e77e59bf8cf ("net: dsa: sja1105: add support for the
SJA1110 switch family") it also has 7.
The point is, between commit 3f01c91aab92 and commit 3e77e59bf8cf, the
driver allocated 8 bytes too few per VLAN retagging entry, or multiplied
by 32 (the value of SJA1105_MAX_RETAGGING_COUNT), it only allocates
enough memory for 27.4 VLAN retagging entries. So any attempt to access
VLAN retagging entries 27-31 in this function would trigger an out of
bounds memory access.
Could you please also send a patch for the "net" tree with this, and the
explanation above?
- table = &priv->static_config.tables[BLK_IDX_VLAN_LOOKUP];
+ table = &priv->static_config.tables[BLK_IDX_RETAGGING];
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][next] net: dsa: sja1105: remove redundant re-assignment of pointer table
2021-07-22 20:05 ` Vladimir Oltean
@ 2021-07-23 12:32 ` Vladimir Oltean
0 siblings, 0 replies; 3+ messages in thread
From: Vladimir Oltean @ 2021-07-23 12:32 UTC (permalink / raw)
To: Colin King
Cc: Andrew Lunn, Vivien Didelot, Florian Fainelli, David S . Miller,
Jakub Kicinski, netdev, kernel-janitors, linux-kernel
On Thu, Jul 22, 2021 at 11:05:44PM +0300, Vladimir Oltean wrote:
> Could you please also send a patch for the "net" tree with this, and the
> explanation above?
>
> - table = &priv->static_config.tables[BLK_IDX_VLAN_LOOKUP];
> + table = &priv->static_config.tables[BLK_IDX_RETAGGING];
I think it's best for me to just send that patch. I will send it towards
the "stable" trees directly, to avoid all sorts of conflicts with "net"
and "net-next" (as mentioned, the VLAN retagging code is going away).
For this patch towards net-next:
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-07-23 12:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-22 19:15 [PATCH][next] net: dsa: sja1105: remove redundant re-assignment of pointer table Colin King
2021-07-22 20:05 ` Vladimir Oltean
2021-07-23 12:32 ` Vladimir Oltean
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).