Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp815902rwb; Mon, 26 Sep 2022 06:16:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7SKVM6e7d3ZHJWvbnEb3j1CPx4QKLTOwysDmiuH573bwBMXxq+UwkiQHvGwB9O7sf70BLH X-Received: by 2002:a17:907:969e:b0:782:6b92:6b1f with SMTP id hd30-20020a170907969e00b007826b926b1fmr15994034ejc.140.1664198218341; Mon, 26 Sep 2022 06:16:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664198218; cv=none; d=google.com; s=arc-20160816; b=a92hgusAlRz7Ye8shWYrC+9RSDzdHEcZ1qPom7vhbNIsDmzxGp4FlF5GeM7F6V7CJS moACn+FMd41y6Y3cn6ft+LIDZA+RougD7L8sr4sQL41qcDj0oAzUnNhlHtChOwbcop7G yxL9HBx7prbmgmTXPhU6vy+Eqwls9n+nVRWRR7xoYFKWrsYJErh3Bqjlh59fYKcJHGvI drruXe0ji95/ICLZTy3dBEXN8tq7ErpWlU7sTkO2e7onxNC6hId3pjn62+EBqFP4wQI7 gmXXFqJso9TvrtX+w2SCxi7flp0oNl9XYbkbHa1v77UOyAh/xyHlvNOndMZbIOtZmCmv nKZg== 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=FP0FGAlgsXmFGfNapMBTq4wmggIWYOUeiv1VDTCggDM=; b=wyHAolgr0OFe2dP21SSNCJ9rnJPGY+jwsz6m0Pes+B6zr7ZSN31zGEfLLyyzwiS3IW 2fQOoSeAOZNR9qx1uo3qX2kGRtVtFY0CNpSEBDH/w3PYTzYG95FNNl6CBGB1fS9Taav4 U9TAdA48uzBPdOTfjqjmTx7mIDl2bIoc9BBVoFeI4otq1trS+XiqxZpgVkw8VX4cnMrk NRXxR+4lLvti+1XHyX9sDiA8T26hbBk6hMahO1BIn/1fBlojknpfv4n4Ot5/7hxTP4+E JcEUuB06DeRaX0LhKPKcj8SKpMD/+Bd1MkRVO2AkUJbXpgWglcyDilVROG3R+gIbhUPJ +65Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=n61sD23q; 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 h30-20020a0564020e9e00b00456ff7eddb3si5677779eda.534.2022.09.26.06.16.32; Mon, 26 Sep 2022 06:16:58 -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=n61sD23q; 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 S235756AbiIZLYm (ORCPT + 99 others); Mon, 26 Sep 2022 07:24:42 -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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 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 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: 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=b5d82a651b71cd8a75ab [1] Reported-by: syzbot Signed-off-by: Tetsuo Handa Tested-by: syzbot Fixes: 43eb8949cfdffa76 ("netfilter: nf_tables: do not leave chain stats enabled 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 = ctx->nla; - struct nft_stats __percpu *stats = NULL; struct nft_table *table = ctx->table; struct nft_base_chain *basechain; struct net *net = ctx->net; @@ -2117,6 +2116,7 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask, return -EOVERFLOW; if (nla[NFTA_CHAIN_HOOK]) { + struct nft_stats __percpu *stats = NULL; struct nft_chain_hook hook; 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; } - if (stats) - static_branch_inc(&nft_counters_enabled); - table->use++; return 0; -- 2.35.1