net: macsec: fix key length when offloading
Subsystems (5)
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
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.
--- drivers/net/macsec.c | 4 ++-- include/net/macsec.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/macsec.c +2 -2
@@ -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
@@ -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
PATCH 2/3 net: phy: mscc: fix macsec key length
In reply to Antoine TenartThe 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).
--- 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
@@ -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
@@ -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
PATCH 3/3 net: atlantic: fix the macsec key length
In reply to Antoine TenartThe 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).
--- 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
@@ -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
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