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 9CD96C4332F for ; Wed, 19 Oct 2022 06:41:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229717AbiJSGl3 (ORCPT ); Wed, 19 Oct 2022 02:41:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229605AbiJSGl1 (ORCPT ); Wed, 19 Oct 2022 02:41:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F053B6D87F for ; Tue, 18 Oct 2022 23:41:24 -0700 (PDT) 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 1EE2961771 for ; Wed, 19 Oct 2022 06:41:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE311C433D6; Wed, 19 Oct 2022 06:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666161671; bh=vc0TJrRmtoaMmoAz6AgTGAh0v075fwFWKs0OJwMgpkc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=N672zkIvW0rWlHmMy6ZJrHZ38Zu4S5ls3k0g6BeOt551prn1JtfFIOhwjxgajgJhL hcaZnkF67pqMsqlfb28U29SnYrff+tZH5duaEqn0huh+47sJlQFlbkftMXwFu7Mrdo Qni/u7hat5cNMq/UwXTfdw/xi7uiqNwqJF9qeLLiot8fe8StrGCBW//VJPuWSL+e0U WWf2LUvWVQ+rkYSqB/vUdnGamnjxqEfVvUkcv2emo2yGBEG7J69GRpy1iHbETDFl0e wAwd4t1MwQpYVkNMYO7Wlese6feWmxZx8zT+vVIOMnMRa3+b6lJXokYM9hnfDVgZZG g0r+1HFsXPlYw== Date: Wed, 19 Oct 2022 09:41:06 +0300 From: Leon Romanovsky To: Saeed Mahameed Cc: "David S . Miller" , Jakub Kicinski , Dan Carpenter , Emeel Hakim , Eric Dumazet , netdev@vger.kernel.org, Paolo Abeni , Raed Salem , Tariq Toukan Subject: Re: [PATCH RESEND net] net/mlx5e: Cleanup MACsec uninitialization routine Message-ID: References: <4bd5c6655c5970ac30adb254a1f09f4f5e992158.1666159448.git.leonro@nvidia.com> <20221019062710.drfqigxhmh3uzxl7@sfedora> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221019062710.drfqigxhmh3uzxl7@sfedora> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Tue, Oct 18, 2022 at 11:27:10PM -0700, Saeed Mahameed wrote: > On 19 Oct 09:06, Leon Romanovsky wrote: > > From: Leon Romanovsky > > > > The mlx5e_macsec_cleanup() routine has pointer dereferencing if mlx5 device > > doesn't support MACsec (priv->macsec will be NULL) together with useless > > comment line, assignment and extra blank lines. > > > > Fix everything in one patch. > > > > Fixes: 1f53da676439 ("net/mlx5e: Create advanced steering operation (ASO) object for MACsec") > > Reported-by: Dan Carpenter > > Signed-off-by: Leon Romanovsky > > --- > > Resend: https://lore.kernel.org/all/b43b1c5aadd5cfdcd2e385ce32693220331700ba.1665645548.git.leonro@nvidia.com > > --- > > .../net/ethernet/mellanox/mlx5/core/en_accel/macsec.c | 11 +---------- > > 1 file changed, 1 insertion(+), 10 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 41970067917b..4331235b21ee 100644 > > --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c > > +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c > > @@ -1846,25 +1846,16 @@ int mlx5e_macsec_init(struct mlx5e_priv *priv) > > void mlx5e_macsec_cleanup(struct mlx5e_priv *priv) > > { > > struct mlx5e_macsec *macsec = priv->macsec; > > - struct mlx5_core_dev *mdev = macsec->mdev; > > + struct mlx5_core_dev *mdev = priv->mdev; > > > > if (!macsec) > > return; > > > > mlx5_notifier_unregister(mdev, &macsec->nb); > > - > > mlx5e_macsec_fs_cleanup(macsec->macsec_fs); > > - > > - /* Cleanup workqueue */ > > destroy_workqueue(macsec->wq); > > - > > mlx5e_macsec_aso_cleanup(&macsec->aso, mdev); > > - > > - priv->macsec = NULL; > > - > > Tariq was right, we need this check, the same priv can be resurrected > after cleanup to be used in switchdev representor profile, where > capabilities are not guaranteed to be the same as NIC netdev, so you will > end up using a garbage macsec. Not really, we are checking that device supports MACsec with mlx5e_is_macsec_device() in every entry call where is a chance do not have priv->macsec. If device doesn't support, the relevant ops won't be installed (mlx5e_macsec_build_netdev) and nothing will call uninitialized MACsec. The NULL assignment is purely anti-pattern where you hide use-after-free access. > > Also we don't submit cleanups to net to avoid porting unnecessary changes > and new bugs to -rc. It is something that was added in previous cycle. There is no backporting yet. Thanks