From nobody Fri Dec 19 17:34:38 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 928A0C07E9D for ; Mon, 26 Sep 2022 11:24:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237809AbiIZLYo (ORCPT ); Mon, 26 Sep 2022 07:24:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237602AbiIZLXS (ORCPT ); Mon, 26 Sep 2022 07:23:18 -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 2A1315FD5; Mon, 26 Sep 2022 03:39:52 -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 0C3B460A36; Mon, 26 Sep 2022 10:38:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11DE1C433D6; Mon, 26 Sep 2022 10:38:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664188719; bh=UQi9LSqABcy467axqnb3ehB0P6+Q+8c9a7f3kN/dJcU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n61sD23qUUxlicppAmkWlAhAEMHpvFQAod2vvJgr/gidq8DG0K/oH4aROzWSX7G2q ZFq4TG+Qrydfea+0dxfLKK9Ls8gIpb4j7RnVmIHZ9GRkYYpLPYEbFdkUMo+kzwm0zd EdtCBkTvi8ipuwAY5D6Al3qpPTAiiDgK+m9JM5gg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Tetsuo Handa , Florian Westphal , Sasha Levin Subject: [PATCH 5.15 100/148] netfilter: nf_tables: fix nft_counters_enabled underflow at nf_tables_addchain() Date: Mon, 26 Sep 2022 12:12:14 +0200 Message-Id: <20220926100759.826985157@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100756.074519146@linuxfoundation.org> References: <20220926100756.074519146@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: Tetsuo Handa [ Upstream commit 921ebde3c0d22c8cba74ce8eb3cc4626abff1ccd ] syzbot is reporting underflow of nft_counters_enabled counter at nf_tables_addchain() [1], for commit 43eb8949cfdffa76 ("netfilter: nf_tables: do not leave chain stats enabled on error") missed that nf_tables_chain_destroy() after nft_basechain_init() in the error path of nf_tables_addchain() decrements the counter because nft_basechain_init() makes nft_is_base_chain() return true by setting NFT_CHAIN_BASE flag. Increment the counter immediately after returning from nft_basechain_init(). Link: https://syzkaller.appspot.com/bug?extid=3Db5d82a651b71cd8a75ab [1] Reported-by: syzbot Signed-off-by: Tetsuo Handa Tested-by: syzbot Fixes: 43eb8949cfdffa76 ("netfilter: nf_tables: do not leave chain stats en= abled on error") Signed-off-by: Florian Westphal Signed-off-by: Sasha Levin --- net/netfilter/nf_tables_api.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index d35d09df83fe..d8e66467c06c 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -2103,7 +2103,6 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8= family, u8 genmask, struct netlink_ext_ack *extack) { const struct nlattr * const *nla =3D ctx->nla; - struct nft_stats __percpu *stats =3D NULL; struct nft_table *table =3D ctx->table; struct nft_base_chain *basechain; struct net *net =3D ctx->net; @@ -2117,6 +2116,7 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8= family, u8 genmask, return -EOVERFLOW; =20 if (nla[NFTA_CHAIN_HOOK]) { + struct nft_stats __percpu *stats =3D NULL; struct nft_chain_hook hook; =20 if (flags & NFT_CHAIN_BINDING) @@ -2150,6 +2150,8 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8= family, u8 genmask, kfree(basechain); return err; } + if (stats) + static_branch_inc(&nft_counters_enabled); } else { if (flags & NFT_CHAIN_BASE) return -EINVAL; @@ -2224,9 +2226,6 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8= family, u8 genmask, goto err_unregister_hook; } =20 - if (stats) - static_branch_inc(&nft_counters_enabled); - table->use++; =20 return 0; --=20 2.35.1