Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1231795imw; Tue, 5 Jul 2022 06:09:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tqC9nUVAfl2dQwqGWCpRZGdSEyqnHZHB0KKRoCEgD4IRUvvGIB2lhO5CQlkaZ3u0v0txGf X-Received: by 2002:a63:3e47:0:b0:40c:f2dd:bc4 with SMTP id l68-20020a633e47000000b0040cf2dd0bc4mr28868736pga.47.1657026564512; Tue, 05 Jul 2022 06:09:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657026564; cv=none; d=google.com; s=arc-20160816; b=FmLq9ZmsKLH5lN46zETip4OXXxV8xsT/h88UTO0ZBtD/kyoTgTLxjYN7jlpJpaaKWN MFiZO0tAhBkLWF8VyJR2DZJUHRJMDGwHkrHesOMg3MxdWebNCOp375rJFAwwYkYILG+N 6u3LCXLnVYAkNOzT9bBFpI5gDoqyIQmAsQA1oR5reqcsu6saR2kaYMSrexMVwvShwEcq l9nunyOLg0tZomxFOolHJlmXzusoQ60mLGmkPiVpl6+WHwThb07vqqIS3XQtinMoWdZG OXoMXvsTYB1ICEdkS4sRkPRt7ceIynUVcW4hEFvNL8VHoTYZNAHLz+bP6ESW7nZ/DnMy 1Pvg== 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=iwk/L+Z5D5lwrcVQIEOtA3n/wESu9m8+037dECX6MhU=; b=ZcM4JbDo9vOaP06CUp9OE8MPSLFiRiqOkvDL+P2GAVUNsXQ/0u71dRA7iJy+kkZkRH ZxE9rcXgNo/yy1mXzP/VXZzXNyHtpmotPjORzo/vPW9kFHiyT5rJQ3k1a6rkWxPyL8lv ZXdHPCjWnj7gxni+o5FgaYoIOvVMtKtKNTt79DQaswkaFj9PS4ANTWRkwaDBNgiI3dC+ S4jqPMMC8+gJO25R+CqrYLosNaZKNxp4MQKKjX2gl8cwRMghOskTerNmOkJpuqKmX9eJ c7HlVzxl0dWHQK0IGUdj3C1XpeRl/BuOxZRn5X37Amy7dxr1/Cs6rz41O2h69HE8bSf3 dfoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VPSaSnGx; 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 n3-20020a170902f60300b00164027788e8si45345705plg.254.2022.07.05.06.09.10; Tue, 05 Jul 2022 06:09:24 -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=VPSaSnGx; 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 S232892AbiGEMAu (ORCPT + 99 others); Tue, 5 Jul 2022 08:00:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232880AbiGEMAW (ORCPT ); Tue, 5 Jul 2022 08:00:22 -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 0302B18345; Tue, 5 Jul 2022 05:00:18 -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 973A66174B; Tue, 5 Jul 2022 12:00:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8CFBC341CF; Tue, 5 Jul 2022 12:00:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657022417; bh=vsaObZd+iZWcxwNohc0sJZuInhfDdn+IkzqXWqIs19g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VPSaSnGxrc5Z/vaWbf60bTZLyJ0hhkJ91Rm35XTphygWFV3F8WTfXPJX/iEGr5JSH ypKK80MgRNhOwRABNZQ8XvC8wYo/HE2vl6nHPpp56J/pFvbIWItXDzEFSUh5c4NxZX vUKhOZAq3VTomN754stumfecnYEiFnQ90e/LmCv8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pablo Neira Ayuso Subject: [PATCH 4.9 09/29] netfilter: nft_dynset: restore set element counter when failing to update Date: Tue, 5 Jul 2022 13:57:50 +0200 Message-Id: <20220705115606.021430942@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220705115605.742248854@linuxfoundation.org> References: <20220705115605.742248854@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 @@ -121,6 +121,7 @@ static bool nft_hash_update(struct nft_s /* 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; } @@ -130,6 +131,7 @@ out: err2: nft_set_elem_destroy(set, he, true); + atomic_dec(&set->nelems); err1: return false; }