Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp3807606rwi; Wed, 2 Nov 2022 03:28:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5WjC1J7cXhleKPL+6mcIsvlV9YU+COsbXUk/G3ynAmFCTXIan2bvzfALUv3IOXHMTP6ZTo X-Received: by 2002:a17:907:980e:b0:78d:b6d5:661e with SMTP id ji14-20020a170907980e00b0078db6d5661emr23159172ejc.46.1667384883636; Wed, 02 Nov 2022 03:28:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667384883; cv=none; d=google.com; s=arc-20160816; b=XtXv8+73Tv7xN0WgDtjbsorMMjle8FUE+krMlrx4GWfytpF/7vCvUThksk0bSmFj0v ind3ZVZujrM+DcTMIHw1UHnkoO7PQWzqkKFuIV04j7YXhkzhjLIz0RHhc/iBiRcUOKle bIqf0psd7MPZUfcMkEHfi7FIqpwbsQCOtaSmXz9ia127RgsD5XkwSlNdRhzL9Up3klMd kbxbd38bSobCp//9tc1LEwkG9I81I0tCO+U7SCaxeE5hhoCj6xX2ckNn1QiKKhjLH/eL 7MQ1stuz2VnjYE87bCnVlEV14/cXVdBHuifbo47Y33jsloKgwIiT/bc7zt1woeEfNg3K uUBA== 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=NZlb/4Id2PtcuaVgVPP5Ts5KzJPWoZZpwgTUspR3bvY=; b=MXFzmw5/tlwoxmZSEXtzOtGed72j6hF771kNjrIlyt9FNrK7ssqZKfDo43TlSzzR6Z Ekb0qK5DR34ZbbqTgHJCcmGdZ74wmIDyhLNsDDUMv3n5XJRjGi9TTIFdFHmO4Z+ctq/W eLwrQFe3WJflLtah1AKGHMjM3nSt0E7BYkDGe5lo/QYtS2UUWYnexjhRjaCEWRsU3OOm o+WKyKpSTdWF+iegWtwJV3CWW630fZc6xN4W2+qmzhtmGhk570xc/2+W6nSOxpuN18eV DjO43cIguK21xmUkQMZ+Pt+UNeD0mtMPI2gWXcVPmQJ3BC0i7V4v6HEnqmU6I3jdP7Ep 1rgg== 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 gt13-20020a1709072d8d00b0078c37681f89si18244947ejc.650.2022.11.02.03.27.39; Wed, 02 Nov 2022 03:28:03 -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 S230045AbiKBJrH (ORCPT + 99 others); Wed, 2 Nov 2022 05:47:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbiKBJrF (ORCPT ); Wed, 2 Nov 2022 05:47:05 -0400 Received: from mail.netfilter.org (mail.netfilter.org [217.70.188.207]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1476823BEE; Wed, 2 Nov 2022 02:47:03 -0700 (PDT) Date: Wed, 2 Nov 2022 10:47:00 +0100 From: Pablo Neira Ayuso To: Chen Zhongjin Cc: linux-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, bpf@vger.kernel.org, kadlec@netfilter.org, fw@strlen.de, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, ast@kernel.org, lorenzo@kernel.org, john.fastabend@gmail.com Subject: Re: [PATCH net v2] netfilter: nf_nat: Fix possible memory leak in nf_nat_init() Message-ID: References: <20221101115252.17340-1-chenzhongjin@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20221101115252.17340-1-chenzhongjin@huawei.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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, Nov 01, 2022 at 07:52:52PM +0800, Chen Zhongjin wrote: > In nf_nat_init(), register_nf_nat_bpf() can fail and return directly > without any error handling. > Then nf_nat_bysource will leak and registering of &nat_net_ops, > &follow_master_nat and nf_nat_hook won't be reverted. > > This leaves wild ops in linkedlists and when another module tries to > call register_pernet_operations() or nf_ct_helper_expectfn_register() > it triggers page fault: > > BUG: unable to handle page fault for address: fffffbfff81b964c > RIP: 0010:register_pernet_operations+0x1b9/0x5f0 > Call Trace: > > register_pernet_subsys+0x29/0x40 > ebtables_init+0x58/0x1000 [ebtables] > ... > > Fixes: 820dc0523e05 ("net: netfilter: move bpf_ct_set_nat_info kfunc in nf_nat_bpf.c") > Signed-off-by: Chen Zhongjin > --- > Also revert the operation for &follow_master_nat and nf_nat_hook, > then slightly fix commit msg for it. Applied, thanks