From nobody Sun Sep 14 22:46:33 2025 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 EE229C54EE9 for ; Tue, 13 Sep 2022 14:38:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234389AbiIMOiA (ORCPT ); Tue, 13 Sep 2022 10:38:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234124AbiIMOf4 (ORCPT ); Tue, 13 Sep 2022 10:35:56 -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 783826B174; Tue, 13 Sep 2022 07:20:20 -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 230DB614D1; Tue, 13 Sep 2022 14:20:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F418C433D6; Tue, 13 Sep 2022 14:20:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663078819; bh=UVbNgyawPUd19OQM4zz3cG21i4z1W30kYpsOwTPZdg8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N2yICOMYfCUmCNUSBNGXgiisDNbFXvtuii189xs6zrCy8c6CJ+uubDVWA8F7Xcoim N0Z2l43BJjNigvGZL3peRe0Cr/dVQndQ9P44o2PezjbDpSb5Pi6Gixp8MtdBvHA5kY Nzb5JRPybNN9+0jg/7umpN64W8VBCKhRxi6uyIvw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+5fcdbfab6d6744c57418@syzkaller.appspotmail.com, Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.15 068/121] netfilter: nf_tables: clean up hook list when offload flags check fails Date: Tue, 13 Sep 2022 16:04:19 +0200 Message-Id: <20220913140400.287305787@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140357.323297659@linuxfoundation.org> References: <20220913140357.323297659@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Pablo Neira Ayuso [ Upstream commit 77972a36ecc4db7fc7c68f0e80714263c5f03f65 ] splice back the hook list so nft_chain_release_hook() has a chance to release the hooks. BUG: memory leak unreferenced object 0xffff88810180b100 (size 96): comm "syz-executor133", pid 3619, jiffies 4294945714 (age 12.690s) hex dump (first 32 bytes): 28 64 23 02 81 88 ff ff 28 64 23 02 81 88 ff ff (d#.....(d#..... 90 a8 aa 83 ff ff ff ff 00 00 b5 0f 81 88 ff ff ................ backtrace: [] kmalloc include/linux/slab.h:600 [inline] [] nft_netdev_hook_alloc+0x3b/0xc0 net/netfilter/nf_t= ables_api.c:1901 [] nft_chain_parse_netdev net/netfilter/nf_tables_api= .c:1998 [inline] [] nft_chain_parse_hook+0x33a/0x530 net/netfilter/nf_= tables_api.c:2073 [] nf_tables_addchain.constprop.0+0x10b/0x950 net/net= filter/nf_tables_api.c:2218 [] nf_tables_newchain+0xa8b/0xc60 net/netfilter/nf_ta= bles_api.c:2593 [] nfnetlink_rcv_batch+0xa46/0xd20 net/netfilter/nfne= tlink.c:517 [] nfnetlink_rcv_skb_batch net/netfilter/nfnetlink.c:= 638 [inline] [] nfnetlink_rcv+0x1f9/0x220 net/netfilter/nfnetlink.= c:656 [] netlink_unicast_kernel net/netlink/af_netlink.c:13= 19 [inline] [] netlink_unicast+0x397/0x4c0 net/netlink/af_netlink= .c:1345 [] netlink_sendmsg+0x396/0x710 net/netlink/af_netlink= .c:1921 [] sock_sendmsg_nosec net/socket.c:714 [inline] [] sock_sendmsg+0x56/0x80 net/socket.c:734 [] ____sys_sendmsg+0x36c/0x390 net/socket.c:2482 [] ___sys_sendmsg+0xa8/0x110 net/socket.c:2536 [] __sys_sendmsg+0x88/0x100 net/socket.c:2565 [] do_syscall_x64 arch/x86/entry/common.c:50 [inline] [] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 [] entry_SYSCALL_64_after_hwframe+0x63/0xcd Fixes: d54725cd11a5 ("netfilter: nf_tables: support for multiple devices pe= r netdev hook") Reported-by: syzbot+5fcdbfab6d6744c57418@syzkaller.appspotmail.com Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nf_tables_api.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index d8ca55d6be409..d35d09df83fee 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -2072,8 +2072,10 @@ static int nft_basechain_init(struct nft_base_chain = *basechain, u8 family, chain->flags |=3D NFT_CHAIN_BASE | flags; basechain->policy =3D NF_ACCEPT; if (chain->flags & NFT_CHAIN_HW_OFFLOAD && - !nft_chain_offload_support(basechain)) + !nft_chain_offload_support(basechain)) { + list_splice_init(&basechain->hook_list, &hook->list); return -EOPNOTSUPP; + } =20 flow_block_init(&basechain->flow_block); =20 --=20 2.35.1