From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE6DD1BB6BE; Tue, 27 Aug 2024 14:55:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724770545; cv=none; b=mcqjboBuvnklILY/oiPCsV1hRUdvSxXCMoYhqYI3Yj+j1a7tWo6ObjyS2SaTgcq2+E3146vtifxo8tnvKKzRODjWjz8/E9+cXcCkQE8sCeVAY1DrndF9N4rswcX1HJ8DOAWA/x7kLSIl9tRyLDr9GWI0sSN3fbFqJlu6DwF2US4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724770545; c=relaxed/simple; bh=28PKdSUUaSN+0n/75/IruCj1nvt2KT2Bj7eYPPaKSRw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l5TBgA2kaBldS1rWnWe5K8SVzzE1WsUVM458USfzCFRZdGgrflrh8INUhU8OCi/sbk8f4/aB/ySgip1LYd/Y6zK70OcnSN3bv4vLl52uEg52aBcGQL93WueOTcJzaSF9g6YkgbYEzLKbZs920YiavW9Lxdb28puSAmrzcG8VIBk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=h9xuDgPj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="h9xuDgPj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13F37C4E699; Tue, 27 Aug 2024 14:55:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1724770545; bh=28PKdSUUaSN+0n/75/IruCj1nvt2KT2Bj7eYPPaKSRw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h9xuDgPjXUCt4CYUWdHP9VxI/9aeeC6a4GF4v03AJpVolZo8IVWdXf9ISJP6U1qRX tVlBfZEHj8H+4fs57WsKIA4iXMBnLr3412MnPVakIIDC4viS1Qc+nQTdYZRWktggJQ +irBI53tHZsdADOTDiKv3HeHKxpQoQz2f8UHD2s8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sebastian Andrzej Siewior , Florian Westphal , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 6.6 253/341] netfilter: nft_counter: Disable BH in nft_counter_offload_stats(). Date: Tue, 27 Aug 2024 16:38:04 +0200 Message-ID: <20240827143853.037882262@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240827143843.399359062@linuxfoundation.org> References: <20240827143843.399359062@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sebastian Andrzej Siewior [ Upstream commit 1eacdd71b3436b54d5fc8218c4bb0187d92a6892 ] The sequence counter nft_counter_seq is a per-CPU counter. There is no lock associated with it. nft_counter_do_eval() is using the same counter and disables BH which suggest that it can be invoked from a softirq. This in turn means that nft_counter_offload_stats(), which disables only preemption, can be interrupted by nft_counter_do_eval() leading to two writer for one seqcount_t. This can lead to loosing stats or reading statistics while they are updated. Disable BH during stats update in nft_counter_offload_stats() to ensure one writer at a time. Fixes: b72920f6e4a9d ("netfilter: nftables: counter hardware offload support") Signed-off-by: Sebastian Andrzej Siewior Reviewed-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nft_counter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/netfilter/nft_counter.c b/net/netfilter/nft_counter.c index dccc68a5135ad..5a90c3c7268bf 100644 --- a/net/netfilter/nft_counter.c +++ b/net/netfilter/nft_counter.c @@ -265,7 +265,7 @@ static void nft_counter_offload_stats(struct nft_expr *expr, struct nft_counter *this_cpu; seqcount_t *myseq; - preempt_disable(); + local_bh_disable(); this_cpu = this_cpu_ptr(priv->counter); myseq = this_cpu_ptr(&nft_counter_seq); @@ -273,7 +273,7 @@ static void nft_counter_offload_stats(struct nft_expr *expr, this_cpu->packets += stats->pkts; this_cpu->bytes += stats->bytes; write_seqcount_end(myseq); - preempt_enable(); + local_bh_enable(); } void nft_counter_init_seqcount(void) -- 2.43.0