From: Vladimir Oltean <olteanv@gmail.com>
To: Colin King <colin.king@canonical.com>
Cc: Andrew Lunn <andrew@lunn.ch>,
Vivien Didelot <vivien.didelot@gmail.com>,
Florian Fainelli <f.fainelli@gmail.com>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
netdev@vger.kernel.org, kernel-janitors@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] net: dsa: sja1105: remove redundant re-assignment of pointer table
Date: Thu, 22 Jul 2021 23:05:44 +0300 [thread overview]
Message-ID: <20210722200544.qvl3sj57qph2whrw@skbuf> (raw)
In-Reply-To: <20210722191529.11013-1-colin.king@canonical.com>
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.
next prev parent reply other threads:[~2021-07-22 20:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2021-07-23 12:32 ` Vladimir Oltean
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=20210722200544.qvl3sj57qph2whrw@skbuf \
--to=olteanv@gmail.com \
--cc=andrew@lunn.ch \
--cc=colin.king@canonical.com \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=vivien.didelot@gmail.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;
as well as URLs for NNTP newsgroup(s).