Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3896142pxv; Tue, 13 Jul 2021 06:23:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwh3VOMRUjXdI5S6VvEMKsOBPF943vZgxrOKvWVUu1zKannvAF11pemEAdbSUO3wxlR2LUq X-Received: by 2002:a92:cb52:: with SMTP id f18mr1596651ilq.97.1626182612302; Tue, 13 Jul 2021 06:23:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626182612; cv=none; d=google.com; s=arc-20160816; b=DZ3wRSshjGTMATkYHvmkHlg+YcFG7y40+jYvtm2TadZyX9YNw/nEOoowhAU8quOYm8 a0FhFi75rmjIFFm/Gv0DptXFv9DPpPFP5FEzUkZ9Pd2GNcvfJDKEoPS6c40M9aB4SAiO vipVXqYeTd/EdYgw9SGRK3OocCxo/eS9e12/5ntg3kbYks1kpjFbVnaKmCQm5db1U/qK enZVtqGz6/gGl2/TiXUew4Ze9RATP78G50xQBY9aBTWSaNdNqH6QCRTFOLX3lt56yi25 iGRwUBPq1uVwdaRpgH+nfQSFsk5qMV68N8PiKKdUnreaR705zzyrK3gbP2R3Tp80O0AP azHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=k/LXyAL4bhLCvnbzMfmCJE+op/qNRsHB1eWYDzZ5+uo=; b=msDDfNxCKIS6Ba2QO3DlfF+xE7hn+RdXx3RXs0ONy+RjdX/yd7LvS648/L9n2Zl+u1 R0whC+neVJOSb5+h+6hl5TS52oJOKg7BrvRSQosSxXoGaVgxro23+tpHp4sqMq9WA891 t1BWEVWzRfDkv6s8CUD8sKpwNL6SXcl25YA363h+rkSy1mrMIDRdSUeuxDGWr1voJHA1 ZBcRB8pngg+V07E6i0ff1JATAN2sK9l43rzqPIs/r1zOg8Ik04kHLWRCxrpXcfjCA1db PGqRIvX/X3vKSH9i7IrmVFPSYdGJMozKRQy8X6Ls+j4sfNebzcHysX6YPTx588ckvBbW 1Bdw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h12si21303351ilc.40.2021.07.13.06.23.19; Tue, 13 Jul 2021 06:23:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236608AbhGMNYI (ORCPT + 99 others); Tue, 13 Jul 2021 09:24:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236283AbhGMNYI (ORCPT ); Tue, 13 Jul 2021 09:24:08 -0400 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:12e:520::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 519ECC0613DD; Tue, 13 Jul 2021 06:21:18 -0700 (PDT) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1m3ILL-0000YP-FG; Tue, 13 Jul 2021 15:20:59 +0200 Date: Tue, 13 Jul 2021 15:20:59 +0200 From: Florian Westphal To: Dongliang Mu Cc: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , Jakub Kicinski , Richard Guy Briggs , Paul Moore , syzbot , kernel test robot , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] audit: fix memory leak in nf_tables_commit Message-ID: <20210713132059.GB11179@breakpoint.cc> References: <20210713130344.473646-1-mudongliangabcd@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210713130344.473646-1-mudongliangabcd@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dongliang Mu wrote: > In nf_tables_commit, if nf_tables_commit_audit_alloc fails, it does not > free the adp variable. > > Fix this by freeing the linked list with head adl. > > backtrace: > kmalloc include/linux/slab.h:591 [inline] > kzalloc include/linux/slab.h:721 [inline] > nf_tables_commit_audit_alloc net/netfilter/nf_tables_api.c:8439 [inline] > nf_tables_commit+0x16e/0x1760 net/netfilter/nf_tables_api.c:8508 > nfnetlink_rcv_batch+0x512/0xa80 net/netfilter/nfnetlink.c:562 > nfnetlink_rcv_skb_batch net/netfilter/nfnetlink.c:634 [inline] > nfnetlink_rcv+0x1fa/0x220 net/netfilter/nfnetlink.c:652 > netlink_unicast_kernel net/netlink/af_netlink.c:1314 [inline] > netlink_unicast+0x2c7/0x3e0 net/netlink/af_netlink.c:1340 > netlink_sendmsg+0x36b/0x6b0 net/netlink/af_netlink.c:1929 > sock_sendmsg_nosec net/socket.c:702 [inline] > sock_sendmsg+0x56/0x80 net/socket.c:722 > > Reported-by: syzbot > Reported-by: kernel test robot > Fixes: c520292f29b8 ("audit: log nftables configuration change events once per table") > Signed-off-by: Dongliang Mu > --- > v1->v2: fix the compile issue > net/netfilter/nf_tables_api.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c > index 390d4466567f..7f45b291be13 100644 > --- a/net/netfilter/nf_tables_api.c > +++ b/net/netfilter/nf_tables_api.c > @@ -8444,6 +8444,16 @@ static int nf_tables_commit_audit_alloc(struct list_head *adl, > return 0; > } > > +static void nf_tables_commit_free(struct list_head *adl) nf_tables_commit_audit_free? Aside from that, there should be a followup patch (for nf-next), adding empty inline functions in case of CONFIG_AUDITSYSCALL=n. Right now it does pointless aggregation for the AUDIT=n case.