Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2663139rwd; Wed, 14 Jun 2023 06:03:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ78J6zNw6NjKI7TYi+h/C3zeaNyaDY6l2xw0TucZU1gStNw7gCc66nX2v8IkFDpsfMNCzXm X-Received: by 2002:a2e:961a:0:b0:2b0:2c9a:a49c with SMTP id v26-20020a2e961a000000b002b02c9aa49cmr6922590ljh.8.1686747806492; Wed, 14 Jun 2023 06:03:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686747806; cv=none; d=google.com; s=arc-20160816; b=gFQ2B4QEfdv3kCcnucPAUFkYuKUmQhA0LYgu4nPHbF6B1lzOJiV/ULsjLcoC41jWC+ Jh/GHtK+auD7s/rprnYiDKE4D21PNBbvgonlayZF0xOmnMVzk5T28A/mdffDEkz5vJKm KjVAGErVCFu9bF9Ks6dfLs94Rh/2iFf5BQ9DkNaQ7lvBxFp2pq8NqHSV+4R37yzjtMjv vKLlR2mtriTvop2Vd7BQYhlgLnz2hSca9o5g0GMB6QcELk3fwsiwSHOuw/oAXwJIvbUn yCjuwBMLrylHn7LYb+17vmAmO1q1dMnYZU8ezTwrvo4bLzJmPWd92uXnQ65C/SwH9Nrj o+aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=qf6GW2z10ZPCt26RK9Ewv1XylyRoAXP0qe2g2uJHHtM=; b=cLAcn6HQhkwe5fFHU8Q2PtWVJlUtIiSsZCJqyLOjYzkodKlrA/1ckoEvdbbBD+P5Mr ApOjz4iM0sqeUOAclq+verubMdyaElLV5011h5GSdhJ4NlFHsKaW9G+lZganYbCYoE84 SXjtVgYkkrM2A0rBTHN7VaidWoP/qHCWNSo+BshyOmifTgquyKAh7jZdF/YMR46WtOsD 42XWBw5oBsg55iqjfCydfc8rQwViyX8M91Wd74qijRMzHwZ+tI1hmbd2s0j7OdOpbmjr WjuCToeQ+OyTZynl/5HbsBAP8yXBAo20OBdY+ou5DBKtsQlpui6XBxzFoQ4ByPXnPM/I saSg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b7-20020a056402138700b00514b1f2da27si8355307edv.222.2023.06.14.06.02.50; Wed, 14 Jun 2023 06:03:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244176AbjFNM13 (ORCPT + 99 others); Wed, 14 Jun 2023 08:27:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235751AbjFNM11 (ORCPT ); Wed, 14 Jun 2023 08:27:27 -0400 X-Greylist: delayed 62 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 14 Jun 2023 05:27:25 PDT Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF46A1FCC for ; Wed, 14 Jun 2023 05:27:25 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-606-OhnLJhs7O2mcDYSWtjXsGg-1; Wed, 14 Jun 2023 08:26:20 -0400 X-MC-Unique: OhnLJhs7O2mcDYSWtjXsGg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E1D008007CE; Wed, 14 Jun 2023 12:26:19 +0000 (UTC) Received: from hog (unknown [10.45.224.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5A1A4492CA6; Wed, 14 Jun 2023 12:26:16 +0000 (UTC) Date: Wed, 14 Jun 2023 14:26:14 +0200 From: Sabrina Dubroca To: Jakub Kicinski Cc: Fedor Pchelkin , "David S. Miller" , Eric Dumazet , Paolo Abeni , Raed Salem , Lior Nahmanson , Saeed Mahameed , Hannes Frederic Sowa , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alexey Khoroshilov , lvc-project@linuxtesting.org Subject: Re: [PATCH] net: macsec: fix double free of percpu stats Message-ID: References: <20230613192220.159407-1-pchelkin@ispras.ru> <20230613200150.361bc462@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230613200150.361bc462@kernel.org> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2023-06-13, 20:01:50 -0700, Jakub Kicinski wrote: > On Tue, 13 Jun 2023 22:22:20 +0300 Fedor Pchelkin wrote: > > Inside macsec_add_dev() we free percpu macsec->secy.tx_sc.stats and > > macsec->stats on some of the memory allocation failure paths. However, the > > net_device is already registered to that moment: in macsec_newlink(), just > > before calling macsec_add_dev(). This means that during unregister process > > its priv_destructor - macsec_free_netdev() - will be called and will free > > the stats again. > > > > Remove freeing percpu stats inside macsec_add_dev() because > > macsec_free_netdev() will correctly free the already allocated ones. The > > pointers to unallocated stats stay NULL, and free_percpu() treats that > > correctly. > > What prevents the device from being opened and used before > macsec_add_dev() has finished? I think we need a fix which > would move this code before register_netdev(), instead :( Can the device be opened in parallel? We're under rtnl here. If we want to move that code, then we'll also have to move the eth_hw_addr_inherit call that's currently in macsec's ndo_init: in case the user didn't give an SCI, we have to make it up based on the device's mac address (dev_to_sci(dev, ...)), whether it's set by the user or inherited. I can't remember if I had a good reason to put the inherit in ndo_init. -- Sabrina