Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2103893rwd; Tue, 13 Jun 2023 20:24:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ48vQTKqUw4h58VAKujU+KR159KQXEuiT/oQ2Pxga/kuFoQ5Gw7YCYWIb7pDfNZtCaH1lEA X-Received: by 2002:a05:6a20:a415:b0:106:feff:71d with SMTP id z21-20020a056a20a41500b00106feff071dmr362751pzk.39.1686713094903; Tue, 13 Jun 2023 20:24:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686713094; cv=none; d=google.com; s=arc-20160816; b=ADSluijhR+f1t+9jODHTR2enjEq4RtJ/SELRbH+VL2L4xnMAKOPjrWx6KpwB1HIcdU nir/W6SLSg4g38EG33z6j+fq7jjx4DVSlgo3tjrCVmKQDwxc5WppLD4VHuUTHYa0E+Uq +WUa1/Ks5Trkp0rkw3Cq9UDNrKU/lxx4RHaGmO9aNYcMjrRbylcdcI/YhaySgmHVpBtG UveuuIwG/pAUKbbdnYNt8AdduxBuwCRrZ/GTfezPVybTrf0s67EJOJI01D1Kr40Aqe7H +rQLaOwSxG9UHnmPx8RlKULcpcBcAlklVmVU1vQSnNvmwUXPDGLVm0O3aSzgnFCTCCr9 cnUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=/HMUfGAdGf/6om9FiHh2Vpym/4By5h0uZyskIrwbmyw=; b=uZw05fpu40HNn7iCdmyAfkXxGH9Az75cdMUfwOw/OYOFNFQ2kQ4Pdsz5tLgUtRWmD+ tx5MbpGJDajjsESHEGx6QcvsnzyNZ3BI/mZddru29dEABYlb8J7AuCkfTPiTHlndFKAl dYfMqN/DofoWN6qLRWEP9KD9gI0g4tLjNBqV6ookJPCYhJJ/tgzW6NrD9lrJkfzPqXjg 7tkEo2NAEHTdyEXQoco/7mGZW2D2my5+ytA5btpU+Ampe/jz21geR/3HHTKT4/T1xME2 t2yJooo+s5dMUpzVzBx81ztDUqmliABhbdsu7UBvLcSz09I5yaNVZyGddfF0podwTv6Q DL7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VJKJOxSM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j4-20020a170903028400b001ab0c00aec4si9673707plr.482.2023.06.13.20.24.40; Tue, 13 Jun 2023 20:24:54 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VJKJOxSM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233905AbjFNDCC (ORCPT + 99 others); Tue, 13 Jun 2023 23:02:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233720AbjFNDBy (ORCPT ); Tue, 13 Jun 2023 23:01:54 -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 555B319A for ; Tue, 13 Jun 2023 20:01:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E000D63D08 for ; Wed, 14 Jun 2023 03:01:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD1A7C433C0; Wed, 14 Jun 2023 03:01:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686711712; bh=J+s2slKhai8XoyOcd8BRcW7AAnL/2RowtfWNsgZlnt4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=VJKJOxSM5D1wAB6WYS0ECG7YcHY4zcGi3xYMdXK87fVWyPnP1yKHuF7vWBX970rRG HvyItXpsHSRlde4DzBOZgkq/AQxNawM8PlEiTGXSXaAaX6Rwt73IhTQISgbQTaq+rC prmJR698iP3uo11HIPQrmLyh2pNxTZoMBwqefazReewy3O3hXL9ms2JfEhKYmMXRc6 s57ctjAqRZYnvVtHMq2NYspE040cDeDN8EGDHw9QJVwzXoMnJikrPIff7AwApStkXN 9DTZzPg0zvD6ZLAE32yeN4bWJCLvxVFJXnIsHDNE8/TlDTnOSz50lek7pAyym7RbPF jmDXVjMZ4bu8w== Date: Tue, 13 Jun 2023 20:01:50 -0700 From: Jakub Kicinski To: Fedor Pchelkin Cc: "David S. Miller" , Sabrina Dubroca , 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: <20230613200150.361bc462@kernel.org> In-Reply-To: <20230613192220.159407-1-pchelkin@ispras.ru> References: <20230613192220.159407-1-pchelkin@ispras.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 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 :( -- pw-bot: cr