netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 0/3] net: macsec: fix key length when offloading
@ 2021-06-24  9:38 Antoine Tenart
  2021-06-24  9:38 ` [PATCH net 1/3] net: macsec: fix the length used to copy the key for offloading Antoine Tenart
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Antoine Tenart @ 2021-06-24  9:38 UTC (permalink / raw)
  To: davem, kuba, sd, andrew, hkallweit1, irusskikh; +Cc: Antoine Tenart, netdev

Hello,

The key length used to copy the key to offloading drivers and to store
it is wrong and was working by chance as it matched the default key
length. But using a different key length fails. Fix it by using instead
the max length accepted in uAPI to store the key and the actual key
length when copying it.

This was tested on the MSCC PHY driver but not on the Atlantic MAC
(looking at the code it looks ok, but testing would be appreciated).

Thanks,
Antoine

Antoine Tenart (3):
  net: macsec: fix the length used to copy the key for offloading
  net: phy: mscc: fix macsec key length
  net: atlantic: fix the macsec key length

 drivers/net/ethernet/aquantia/atlantic/aq_macsec.h | 4 ++--
 drivers/net/macsec.c                               | 4 ++--
 drivers/net/phy/mscc/mscc_macsec.c                 | 2 +-
 drivers/net/phy/mscc/mscc_macsec.h                 | 2 +-
 include/net/macsec.h                               | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net 1/3] net: macsec: fix the length used to copy the key for offloading
  2021-06-24  9:38 [PATCH net 0/3] net: macsec: fix key length when offloading Antoine Tenart
@ 2021-06-24  9:38 ` Antoine Tenart
  2021-06-24  9:38 ` [PATCH net 2/3] net: phy: mscc: fix macsec key length Antoine Tenart
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Antoine Tenart @ 2021-06-24  9:38 UTC (permalink / raw)
  To: davem, kuba, sd, andrew, hkallweit1, irusskikh
  Cc: Antoine Tenart, netdev, Lior Nahmanson

The key length used when offloading macsec to Ethernet or PHY drivers
was set to MACSEC_KEYID_LEN (16), which is an issue as:
- This was never meant to be the key length.
- The key length can be > 16.

Fix this by using MACSEC_MAX_KEY_LEN to store the key (the max length
accepted in uAPI) and secy->key_len to copy it.

Fixes: 3cf3227a21d1 ("net: macsec: hardware offloading infrastructure")
Reported-by: Lior Nahmanson <liorna@nvidia.com>
Signed-off-by: Antoine Tenart <atenart@kernel.org>
---
 drivers/net/macsec.c | 4 ++--
 include/net/macsec.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
index 92425e1fd70c..93dc48b9b4f2 100644
--- a/drivers/net/macsec.c
+++ b/drivers/net/macsec.c
@@ -1819,7 +1819,7 @@ static int macsec_add_rxsa(struct sk_buff *skb, struct genl_info *info)
 		ctx.sa.rx_sa = rx_sa;
 		ctx.secy = secy;
 		memcpy(ctx.sa.key, nla_data(tb_sa[MACSEC_SA_ATTR_KEY]),
-		       MACSEC_KEYID_LEN);
+		       secy->key_len);
 
 		err = macsec_offload(ops->mdo_add_rxsa, &ctx);
 		if (err)
@@ -2061,7 +2061,7 @@ static int macsec_add_txsa(struct sk_buff *skb, struct genl_info *info)
 		ctx.sa.tx_sa = tx_sa;
 		ctx.secy = secy;
 		memcpy(ctx.sa.key, nla_data(tb_sa[MACSEC_SA_ATTR_KEY]),
-		       MACSEC_KEYID_LEN);
+		       secy->key_len);
 
 		err = macsec_offload(ops->mdo_add_txsa, &ctx);
 		if (err)
diff --git a/include/net/macsec.h b/include/net/macsec.h
index 52874cdfe226..d6fa6b97f6ef 100644
--- a/include/net/macsec.h
+++ b/include/net/macsec.h
@@ -241,7 +241,7 @@ struct macsec_context {
 	struct macsec_rx_sc *rx_sc;
 	struct {
 		unsigned char assoc_num;
-		u8 key[MACSEC_KEYID_LEN];
+		u8 key[MACSEC_MAX_KEY_LEN];
 		union {
 			struct macsec_rx_sa *rx_sa;
 			struct macsec_tx_sa *tx_sa;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net 2/3] net: phy: mscc: fix macsec key length
  2021-06-24  9:38 [PATCH net 0/3] net: macsec: fix key length when offloading Antoine Tenart
  2021-06-24  9:38 ` [PATCH net 1/3] net: macsec: fix the length used to copy the key for offloading Antoine Tenart
@ 2021-06-24  9:38 ` Antoine Tenart
  2021-06-24  9:38 ` [PATCH net 3/3] net: atlantic: fix the " Antoine Tenart
  2021-06-24 19:50 ` [PATCH net 0/3] net: macsec: fix key length when offloading patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Antoine Tenart @ 2021-06-24  9:38 UTC (permalink / raw)
  To: davem, kuba, sd, andrew, hkallweit1, irusskikh
  Cc: Antoine Tenart, netdev, Lior Nahmanson

The key length used to store the macsec key was set to MACSEC_KEYID_LEN
(16), which is an issue as:
- This was never meant to be the key length.
- The key length can be > 16.

Fix this by using MACSEC_MAX_KEY_LEN instead (the max length accepted in
uAPI).

Fixes: 28c5107aa904 ("net: phy: mscc: macsec support")
Reported-by: Lior Nahmanson <liorna@nvidia.com>
Signed-off-by: Antoine Tenart <atenart@kernel.org>
---
 drivers/net/phy/mscc/mscc_macsec.c | 2 +-
 drivers/net/phy/mscc/mscc_macsec.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/mscc/mscc_macsec.c b/drivers/net/phy/mscc/mscc_macsec.c
index 10be266e48e8..b7b2521c73fb 100644
--- a/drivers/net/phy/mscc/mscc_macsec.c
+++ b/drivers/net/phy/mscc/mscc_macsec.c
@@ -501,7 +501,7 @@ static u32 vsc8584_macsec_flow_context_id(struct macsec_flow *flow)
 }
 
 /* Derive the AES key to get a key for the hash autentication */
-static int vsc8584_macsec_derive_key(const u8 key[MACSEC_KEYID_LEN],
+static int vsc8584_macsec_derive_key(const u8 key[MACSEC_MAX_KEY_LEN],
 				     u16 key_len, u8 hkey[16])
 {
 	const u8 input[AES_BLOCK_SIZE] = {0};
diff --git a/drivers/net/phy/mscc/mscc_macsec.h b/drivers/net/phy/mscc/mscc_macsec.h
index 9c6d25e36de2..453304bae778 100644
--- a/drivers/net/phy/mscc/mscc_macsec.h
+++ b/drivers/net/phy/mscc/mscc_macsec.h
@@ -81,7 +81,7 @@ struct macsec_flow {
 	/* Highest takes precedence [0..15] */
 	u8 priority;
 
-	u8 key[MACSEC_KEYID_LEN];
+	u8 key[MACSEC_MAX_KEY_LEN];
 
 	union {
 		struct macsec_rx_sa *rx_sa;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net 3/3] net: atlantic: fix the macsec key length
  2021-06-24  9:38 [PATCH net 0/3] net: macsec: fix key length when offloading Antoine Tenart
  2021-06-24  9:38 ` [PATCH net 1/3] net: macsec: fix the length used to copy the key for offloading Antoine Tenart
  2021-06-24  9:38 ` [PATCH net 2/3] net: phy: mscc: fix macsec key length Antoine Tenart
@ 2021-06-24  9:38 ` Antoine Tenart
  2021-06-24 19:50 ` [PATCH net 0/3] net: macsec: fix key length when offloading patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Antoine Tenart @ 2021-06-24  9:38 UTC (permalink / raw)
  To: davem, kuba, sd, andrew, hkallweit1, irusskikh
  Cc: Antoine Tenart, netdev, Lior Nahmanson

The key length used to store the macsec key was set to MACSEC_KEYID_LEN
(16), which is an issue as:
- This was never meant to be the key length.
- The key length can be > 16.

Fix this by using MACSEC_MAX_KEY_LEN instead (the max length accepted in
uAPI).

Fixes: 27736563ce32 ("net: atlantic: MACSec egress offload implementation")
Fixes: 9ff40a751a6f ("net: atlantic: MACSec ingress offload implementation")
Reported-by: Lior Nahmanson <liorna@nvidia.com>
Signed-off-by: Antoine Tenart <atenart@kernel.org>
---
 drivers/net/ethernet/aquantia/atlantic/aq_macsec.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_macsec.h b/drivers/net/ethernet/aquantia/atlantic/aq_macsec.h
index f5fba8b8cdea..a47e2710487e 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_macsec.h
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_macsec.h
@@ -91,7 +91,7 @@ struct aq_macsec_txsc {
 	u32 hw_sc_idx;
 	unsigned long tx_sa_idx_busy;
 	const struct macsec_secy *sw_secy;
-	u8 tx_sa_key[MACSEC_NUM_AN][MACSEC_KEYID_LEN];
+	u8 tx_sa_key[MACSEC_NUM_AN][MACSEC_MAX_KEY_LEN];
 	struct aq_macsec_tx_sc_stats stats;
 	struct aq_macsec_tx_sa_stats tx_sa_stats[MACSEC_NUM_AN];
 };
@@ -101,7 +101,7 @@ struct aq_macsec_rxsc {
 	unsigned long rx_sa_idx_busy;
 	const struct macsec_secy *sw_secy;
 	const struct macsec_rx_sc *sw_rxsc;
-	u8 rx_sa_key[MACSEC_NUM_AN][MACSEC_KEYID_LEN];
+	u8 rx_sa_key[MACSEC_NUM_AN][MACSEC_MAX_KEY_LEN];
 	struct aq_macsec_rx_sa_stats rx_sa_stats[MACSEC_NUM_AN];
 };
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net 0/3] net: macsec: fix key length when offloading
  2021-06-24  9:38 [PATCH net 0/3] net: macsec: fix key length when offloading Antoine Tenart
                   ` (2 preceding siblings ...)
  2021-06-24  9:38 ` [PATCH net 3/3] net: atlantic: fix the " Antoine Tenart
@ 2021-06-24 19:50 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-06-24 19:50 UTC (permalink / raw)
  To: Antoine Tenart; +Cc: davem, kuba, sd, andrew, hkallweit1, irusskikh, netdev

Hello:

This series was applied to netdev/net.git (refs/heads/master):

On Thu, 24 Jun 2021 11:38:27 +0200 you wrote:
> Hello,
> 
> The key length used to copy the key to offloading drivers and to store
> it is wrong and was working by chance as it matched the default key
> length. But using a different key length fails. Fix it by using instead
> the max length accepted in uAPI to store the key and the actual key
> length when copying it.
> 
> [...]

Here is the summary with links:
  - [net,1/3] net: macsec: fix the length used to copy the key for offloading
    https://git.kernel.org/netdev/net/c/1f7fe5121127
  - [net,2/3] net: phy: mscc: fix macsec key length
    https://git.kernel.org/netdev/net/c/c309217f91f2
  - [net,3/3] net: atlantic: fix the macsec key length
    https://git.kernel.org/netdev/net/c/d67fb4772d9a

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-24 19:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-24  9:38 [PATCH net 0/3] net: macsec: fix key length when offloading Antoine Tenart
2021-06-24  9:38 ` [PATCH net 1/3] net: macsec: fix the length used to copy the key for offloading Antoine Tenart
2021-06-24  9:38 ` [PATCH net 2/3] net: phy: mscc: fix macsec key length Antoine Tenart
2021-06-24  9:38 ` [PATCH net 3/3] net: atlantic: fix the " Antoine Tenart
2021-06-24 19:50 ` [PATCH net 0/3] net: macsec: fix key length when offloading patchwork-bot+netdevbpf

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).