Skip to contentSkip to conversation

net: macsec: fix key length when offloading

PATCH Applied Antoine Tenart 2 participants 5 messages Jun 24, 2021

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover net: macsec: fix key length when offloading

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(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/3 net: macsec: fix the length used to copy the key for offloading

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")
---
 drivers/net/macsec.c | 4 ++--
 include/net/macsec.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/macsec.c +2 -2
index 92425e1fd70c..93dc48b9b4f2 100644
@@ -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)
include/net/macsec.h +1 -1
index 52874cdfe226..d6fa6b97f6ef 100644
@@ -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;
Signature · 1 line
2.31.1
#2 lore raw

PATCH 2/3 net: phy: mscc: fix macsec key length

In reply to Antoine Tenart

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")
---
 drivers/net/phy/mscc/mscc_macsec.c | 2 +-
 drivers/net/phy/mscc/mscc_macsec.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/phy/mscc/mscc_macsec.c +1 -1
index 10be266e48e8..b7b2521c73fb 100644
@@ -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};
drivers/net/phy/mscc/mscc_macsec.h +1 -1
index 9c6d25e36de2..453304bae778 100644
@@ -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;
Signature · 1 line
2.31.1
#3 lore raw

PATCH 3/3 net: atlantic: fix the macsec key length

In reply to Antoine Tenart

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")
---
 drivers/net/ethernet/aquantia/atlantic/aq_macsec.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/aquantia/atlantic/aq_macsec.h +2 -2
index f5fba8b8cdea..a47e2710487e 100644
@@ -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];
 };
 
Signature · 1 line
2.31.1
#4 lore raw
In reply to Antoine Tenart
This series was applied to netdev/net.git (refs/heads/master):

Hello:

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

Quoted 9 lines · 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