Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6830910rwn; Tue, 13 Sep 2022 09:32:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR4g1H7bOAQYexClkBnYxMCDjrZE3fVcvtVGg3wO3CraG2GdC3NStMu91h8XgD/XCH8l5clI X-Received: by 2002:a17:906:4fc3:b0:72e:eab4:d9d7 with SMTP id i3-20020a1709064fc300b0072eeab4d9d7mr22211698ejw.599.1663086752303; Tue, 13 Sep 2022 09:32:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663086752; cv=none; d=google.com; s=arc-20160816; b=ctCj0dvhS4aCvLP0kieqD100gXNnm3Mv17CZuy9AB3swQA4NSCV8Ttdoy2ypaYF52y kJOi4VXbLf9ostvkLJ5eKJSv4HFHObBee+oNA/a8K8AHSAK7o7HKncEISmEXqgUagRz3 I0F7l4CxkiwOIUhKJe9zLs+H5msqY4711dpza4ZRicSvKFly+VSXzJFZPj02lUSkpYGa XXVVcRA98dlB+BIUZmRVSZ4kN8/mi3J7nVw3bYaT4ZHvFnBou9+Zf5fPE+rboWW4+X8/ s4KdObGhZAtOOXT0N6uqsyEANZy6v8v8I2zRsLb2qS3mwzVqwnx1CXh36/Nz6bcf7UzH DxSg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=f5e0bAO4e1QTbNoQexitroRCnGBrnKMdg/yNMqZLXyU=; b=emM4kGSmaF4XaKFTvpdcc/rAga+XPA8TMAqklKZKk2cL/4iee5fbDMDSAv+ncTS+mf 0ZkGfmDuMymlTs4SsYt174UJVQdv1qW7oCEPS4kKCSfdSXl0hNky2ZOBrQILlQeTrKLK v2YNRYEeq3kTktzj+htwDVsH1e6PNlETgnUpTWU01dLPo1nX/Y3SQnOEXoTSyjRR2JfY Q3v/lPPb2Dgu80fc4jvjsFsHa1eS+V6wtipCCaLHm2+LTVG+aaBRojli4tJGT8QDaz7o wotOrUyo+8WzFpBYGN1gvcGmr9jzUDCi3BHCoz2uBTvo4m0oeDLfGZUdSLIDOQbmCm/q +7tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pxk4xNud; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w20-20020a056402269400b0044f3b9ef98bsi10218163edd.27.2022.09.13.09.31.54; Tue, 13 Sep 2022 09:32:32 -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=@linuxfoundation.org header.s=korg header.b=pxk4xNud; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230119AbiIMOrD (ORCPT + 99 others); Tue, 13 Sep 2022 10:47:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234565AbiIMOn7 (ORCPT ); Tue, 13 Sep 2022 10:43:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90C496EF38; Tue, 13 Sep 2022 07:23:37 -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 ams.source.kernel.org (Postfix) with ESMTPS id DE504B80E22; Tue, 13 Sep 2022 14:23:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 482FEC433D6; Tue, 13 Sep 2022 14:23:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079015; bh=UI+gRuv3zcDmPY0ND7q4jXM2pRFR+veYZDyYtkFqn/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pxk4xNudGlRlt5SiVD98GT4DrmEki2HvSHEsDc9j0K/SAvjt5m3P1tbHnQtwzKlCx bszeNT07iJERqyDdXpg7HbyUDtEj9uQXvaDgA/m5PaLnsiFR79c4Uk/lu5E/Ryyv9M SNNTpdodmkEoXoe466uRLApNQmKe39iI5sOZwDG8= 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.10 49/79] netfilter: nf_tables: clean up hook list when offload flags check fails Date: Tue, 13 Sep 2022 16:04:54 +0200 Message-Id: <20220913140352.621056306@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140350.291927556@linuxfoundation.org> References: <20220913140350.291927556@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 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_tables_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/netfilter/nf_tables_api.c:2218 [] nf_tables_newchain+0xa8b/0xc60 net/netfilter/nf_tables_api.c:2593 [] nfnetlink_rcv_batch+0xa46/0xd20 net/netfilter/nfnetlink.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:1319 [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 per 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 1b039476e4d6a..b8e7e1c5c08a8 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -1971,8 +1971,10 @@ static int nft_basechain_init(struct nft_base_chain *basechain, u8 family, chain->flags |= NFT_CHAIN_BASE | flags; basechain->policy = 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; + } flow_block_init(&basechain->flow_block); -- 2.35.1