Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1254940imw; Tue, 5 Jul 2022 06:30:36 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vk11byRsgWRN2uYViC/6xw+LqFeEhj44CLfxwpURXgr25AsdpbTBRcO9vnzB6bCkoea7Ok X-Received: by 2002:aa7:df12:0:b0:43a:4991:1725 with SMTP id c18-20020aa7df12000000b0043a49911725mr16560528edy.55.1657027836784; Tue, 05 Jul 2022 06:30:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657027836; cv=none; d=google.com; s=arc-20160816; b=jYjacrwYedlYUOn5KgLeLjGv8/ad7uWfyYbKmsCKmI/LdvZ1T+Q33+yLS6N0QFfHWs AFWtP8Oa7JiptQr8HTcqRJH1YLKSfnmHxxb5ZeLHZxbZ/l5k5b3Mnsptwlf1EPaw+C0x 3Nf+i019tUaERW8+te1+9y/VDIs1nnai9/jer/SPhpWXBzsm4ZhaJZU50G4ge/nzVN9i /7qab5nUfL+PmBSWVWzZC88pg2Bdak10Peq+clfId82TE30ee0FvGLq7FmhW/6zGHzgd juSmc1A/3kHLxyc+sZG+QgA8kjgu7ika7Gz0OKHmEix4+jwvKyyxZOyPgCenoZkQVutd Vv3Q== 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=NlJEOEotar9Wzt4ohQi4kkCq9EnE0fLNfBfjK10OJfs=; b=JT9Z2d6eKfDXI0NnTFrBOPUGv3zy9cnltJoMECXP7bNxZY4+DJLXhsK9/FESlHNzI1 588z8WBOzF/fV5KvvzeQB+qd98oup/YVmN71wvO9ORWf94v6tnjHbiErbuRztOc4gWg/ M4YFiPGd5QezEWknp47PrOzEqdyza8elr8q+IswaB10NiihxhnRD2LymCJOmLHRVw+XO fm7nbrUQIds0GtR69VsebJ4jx5i9S3LO+0repCcwiWkgOZY3BrOXCAd6larMUI3HGkK0 xMVvhpP5ppoXKrJSK9gmvchyXsan+c4/sZYw1jfLJUipQuYlPhmWj0mc4kwText0BcDo 4N+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HARoK6dA; 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 w16-20020aa7d290000000b0043a80497ebdsi134618edq.379.2022.07.05.06.30.11; Tue, 05 Jul 2022 06:30:36 -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=HARoK6dA; 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 S235743AbiGEMOr (ORCPT + 99 others); Tue, 5 Jul 2022 08:14:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235032AbiGEMIW (ORCPT ); Tue, 5 Jul 2022 08:08:22 -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 7511D18B07; Tue, 5 Jul 2022 05:07:29 -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 10901B817CE; Tue, 5 Jul 2022 12:07:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62CE7C341C7; Tue, 5 Jul 2022 12:07:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657022846; bh=re5Wn/xk178YJ83mwsFNrjU0QkkAsrlDr4J0Cv/IOHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HARoK6dArLwux7okW5rJN5SPhqBRkwJGF2FiBUU9lUShB/O8EpWSk0vL9qPBefXCd x6Z+JJcMWh/7L+te3N5oP8yw+qCMJ80EX/8vNFMkLbu1PdGHGdasthplg6T3OMIvlh +c53zCeBK+A1ojgq23FsWxpxu2x0s9SPjBKL2s2E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pablo Neira Ayuso Subject: [PATCH 5.10 30/84] netfilter: nft_dynset: restore set element counter when failing to update Date: Tue, 5 Jul 2022 13:57:53 +0200 Message-Id: <20220705115616.204110847@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220705115615.323395630@linuxfoundation.org> References: <20220705115615.323395630@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 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 commit 05907f10e235680cc7fb196810e4ad3215d5e648 upstream. This patch fixes a race condition. nft_rhash_update() might fail for two reasons: - Element already exists in the hashtable. - Another packet won race to insert an entry in the hashtable. In both cases, new() has already bumped the counter via atomic_add_unless(), therefore, decrement the set element counter. Fixes: 22fe54d5fefc ("netfilter: nf_tables: add support for dynamic set updates") Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nft_set_hash.c | 2 ++ 1 file changed, 2 insertions(+) --- a/net/netfilter/nft_set_hash.c +++ b/net/netfilter/nft_set_hash.c @@ -142,6 +142,7 @@ static bool nft_rhash_update(struct nft_ /* Another cpu may race to insert the element with the same key */ if (prev) { nft_set_elem_destroy(set, he, true); + atomic_dec(&set->nelems); he = prev; } @@ -151,6 +152,7 @@ out: err2: nft_set_elem_destroy(set, he, true); + atomic_dec(&set->nelems); err1: return false; }