From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC9AAC46467 for ; Tue, 10 Jan 2023 06:12:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234571AbjAJGM5 (ORCPT ); Tue, 10 Jan 2023 01:12:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230094AbjAJGMS (ORCPT ); Tue, 10 Jan 2023 01:12:18 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9EEF43A2F for ; Mon, 9 Jan 2023 22:11:53 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 548E8614E5 for ; Tue, 10 Jan 2023 06:11:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B0C1C433EF; Tue, 10 Jan 2023 06:11:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673331112; bh=A2FtlxvhVni3+Q/68Bwt84O/kLNzEDqvZEBfXhLWuXU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uAzI5ukdP2ibnjxojSWhhCY/ywQ2WsJ1537IJ416FMHJ8EGKgkuJ37Xe9+QWaF6rD 6ttXytC+Fx0C5Doaig3Ntt9pbXVnWeyUouFaiFyqaTPtIfxh79Vmhis8NdyqYtkrfk 3isLAwgf0H6INu5VnVa/2/qVpsSZudqiUjQZ2LupB+qH+TSq3KIEM/C0iTskuDH6+H fg6p6T4eF8YkK65ho6ZbLgYnvJK6rHpzgj0xYeRzPkAdlR1JDeiQMhXEN2bMdBur3/ k5nJL0hd72R/j4iCQPXQhxLLwAulk1bIM6mAbghH+UXvndDNA+NvbGWrmNz3SmCnXE 3Ga8kbK7vzwHA== From: Saeed Mahameed To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: Saeed Mahameed , netdev@vger.kernel.org, Tariq Toukan , Emeel Hakim , Raed Salem Subject: [net 16/16] net/mlx5e: Fix macsec possible null dereference when updating MAC security entity (SecY) Date: Mon, 9 Jan 2023 22:11:23 -0800 Message-Id: <20230110061123.338427-17-saeed@kernel.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230110061123.338427-1-saeed@kernel.org> References: <20230110061123.338427-1-saeed@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Emeel Hakim Upon updating MAC security entity (SecY) in hw offload path, the macsec security association (SA) initialization routine is called. In case of extended packet number (epn) is enabled the salt and ssci attributes are retrieved using the MACsec driver rx_sa context which is unavailable when updating a SecY property such as encoding-sa hence the null dereference. Fix by using the provided SA to set those attributes. Fixes: 4411a6c0abd3 ("net/mlx5e: Support MACsec offload extended packet number (EPN)") Signed-off-by: Emeel Hakim Reviewed-by: Raed Salem Signed-off-by: Saeed Mahameed --- .../net/ethernet/mellanox/mlx5/core/en_accel/macsec.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c index cf7b3bb54c86..7f6b940830b3 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c @@ -359,7 +359,6 @@ static int mlx5e_macsec_init_sa(struct macsec_context *ctx, struct mlx5_core_dev *mdev = priv->mdev; struct mlx5_macsec_obj_attrs obj_attrs; union mlx5e_macsec_rule *macsec_rule; - struct macsec_key *key; int err; obj_attrs.next_pn = sa->next_pn; @@ -369,13 +368,9 @@ static int mlx5e_macsec_init_sa(struct macsec_context *ctx, obj_attrs.aso_pdn = macsec->aso.pdn; obj_attrs.epn_state = sa->epn_state; - key = (is_tx) ? &ctx->sa.tx_sa->key : &ctx->sa.rx_sa->key; - if (sa->epn_state.epn_enabled) { - obj_attrs.ssci = (is_tx) ? cpu_to_be32((__force u32)ctx->sa.tx_sa->ssci) : - cpu_to_be32((__force u32)ctx->sa.rx_sa->ssci); - - memcpy(&obj_attrs.salt, &key->salt, sizeof(key->salt)); + obj_attrs.ssci = cpu_to_be32((__force u32)sa->ssci); + memcpy(&obj_attrs.salt, &sa->salt, sizeof(sa->salt)); } obj_attrs.replay_window = ctx->secy->replay_window; -- 2.39.0