From patchwork Thu Jun 24 09:38:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 12341669 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD642C48BDF for ; Thu, 24 Jun 2021 09:38:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A1D77613FB for ; Thu, 24 Jun 2021 09:38:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231978AbhFXJkz (ORCPT ); Thu, 24 Jun 2021 05:40:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:54640 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230299AbhFXJky (ORCPT ); Thu, 24 Jun 2021 05:40:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7FA28613F7; Thu, 24 Jun 2021 09:38:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624527516; bh=j9LKsxTjE7kLy/riQPudALCo1NepgJYKTZyqAjzyA7o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ya3pQleo2NTskmiHEFPKJfSywFmHL2cVFcUs8sWnnq2WcaJu7KYvdf5DDaXZVgCFM A2vGg5Dr4hpk4SKRq0Ng/fcXCRAG2fhl5NzgAiOonpm5QTF76+bc1T3ZmPvKwRT1Lh ugKvqTOhq9U8zGIEYndaD6McFvR/4jR1owlyotBkpXXGAtYV4bZwObmAmZuQ7bzq9X 2mFyZqrMjrkswFcsUVEkEDm+AnBJf6fL2qj151fhA2MT+bk424dKVJ72ZHnI6CBH6q bAw9Pcfrdgx/JWysqt+Yx403gcc82KkeK0/W+mh1BWconPek5caPZI7smTjYN7x0sh 8z/rWttjc3MDA== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org, sd@queasysnail.net, andrew@lunn.ch, hkallweit1@gmail.com, irusskikh@marvell.com Cc: Antoine Tenart , netdev@vger.kernel.org, Lior Nahmanson Subject: [PATCH net 1/3] net: macsec: fix the length used to copy the key for offloading Date: Thu, 24 Jun 2021 11:38:28 +0200 Message-Id: <20210624093830.943139-2-atenart@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210624093830.943139-1-atenart@kernel.org> References: <20210624093830.943139-1-atenart@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 Signed-off-by: Antoine Tenart --- 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; From patchwork Thu Jun 24 09:38:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 12341671 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 149C5C48BDF for ; Thu, 24 Jun 2021 09:38:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E7CD7613F6 for ; Thu, 24 Jun 2021 09:38:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231985AbhFXJlA (ORCPT ); Thu, 24 Jun 2021 05:41:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:54700 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230299AbhFXJk5 (ORCPT ); Thu, 24 Jun 2021 05:40:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5EC58613F6; Thu, 24 Jun 2021 09:38:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624527519; bh=nroBsKWJJxUHBe+pmBgTlAGQCdIlIewQPm2Pf4A08kM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P0IvcPRrCKY1ctUT8YQxQA9LjVshQoXoFCmz5E080rRilk3yrDEVGKVeluUoY5wep lmeF3sUw9ib+ON8XDvd0GdSUzQvVNzWrJuzB9igGqMHfnZEke9iA/SzkTO5STiDk8y CXeNFzNptuC5DT9kv0a2avKd7vhpNmZ4axVhhjlFEhNlv58oUa97ou4piW1y1JIvSi HtnkYVhxK6AlVZgIgEvvyK3UeSc3x3ZGVr8HXMgbiw0czrhN6fwbjhEJn4ihVqB7Lz nALBSyN4Aung8t+6Hx+3eZec2UPsaEvqOZw/aJplib6CulCrsmCk+2CvFmoHvylcdC wpIFBQSaDPlUw== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org, sd@queasysnail.net, andrew@lunn.ch, hkallweit1@gmail.com, irusskikh@marvell.com Cc: Antoine Tenart , netdev@vger.kernel.org, Lior Nahmanson Subject: [PATCH net 2/3] net: phy: mscc: fix macsec key length Date: Thu, 24 Jun 2021 11:38:29 +0200 Message-Id: <20210624093830.943139-3-atenart@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210624093830.943139-1-atenart@kernel.org> References: <20210624093830.943139-1-atenart@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 Signed-off-by: Antoine Tenart --- 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; From patchwork Thu Jun 24 09:38:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 12341673 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14011C48BDF for ; Thu, 24 Jun 2021 09:38:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EEB8C613F6 for ; Thu, 24 Jun 2021 09:38:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232002AbhFXJlB (ORCPT ); Thu, 24 Jun 2021 05:41:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:54734 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231992AbhFXJlA (ORCPT ); Thu, 24 Jun 2021 05:41:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3E50B613F7; Thu, 24 Jun 2021 09:38:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624527521; bh=pdW2QVi5lgMgtuRwExp4AtoMBgqeclkOLDlxZrbEIhY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hcsV+5QLm13OIep0WPtIlNNhz6J03D72zVdG1vkwmRJpPVquPpyNRLNPtFvYwJv0o apXYgL1yN+HLaX/h3UWo7hxAAJVCcLHavlnWz5ukeUSM9Momwi7st18q+SFca+rbDg EqGsdcxzLSw1PaZZsL7MtK6gYQalS+McFLd6z2WvpFulB/mCF4oLgt/PEx9YhQ2ZFp bb0/6AxyEgBH8zxz4O10+k/9Lm+Kt90edfq2LOXe1K3NC2MhP/g7xjNQN/IPYUFErY 0+ChF/8uW6D9NkLKFKKDyst7iAMtqjNq4mIo3KINRmhlrVykRBYum9DCE+3Y77to5h lbx4sHkXNpJYg== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org, sd@queasysnail.net, andrew@lunn.ch, hkallweit1@gmail.com, irusskikh@marvell.com Cc: Antoine Tenart , netdev@vger.kernel.org, Lior Nahmanson Subject: [PATCH net 3/3] net: atlantic: fix the macsec key length Date: Thu, 24 Jun 2021 11:38:30 +0200 Message-Id: <20210624093830.943139-4-atenart@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210624093830.943139-1-atenart@kernel.org> References: <20210624093830.943139-1-atenart@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 Signed-off-by: Antoine Tenart --- 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]; };