]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
netfilter: nft_ct: Use __refcount_inc() for per-CPU nft_ct_pcpu_template.
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Mon, 17 Feb 2025 16:02:42 +0000 (17:02 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Apr 2025 12:31:48 +0000 (14:31 +0200)
commit595e855a0f38249823a811e991023dfd110797b0
treec0c8b01f6505b487fc7bb46f5b7c5dc605b674f2
parent10e33014552c45b80c87c984235b4e14a65ad584
netfilter: nft_ct: Use __refcount_inc() for per-CPU nft_ct_pcpu_template.

[ Upstream commit 5cfe5612ca9590db69b9be29dc83041dbf001108 ]

nft_ct_pcpu_template is a per-CPU variable and relies on disabled BH for its
locking. The refcounter is read and if its value is set to one then the
refcounter is incremented and variable is used - otherwise it is already
in use and left untouched.

Without per-CPU locking in local_bh_disable() on PREEMPT_RT the
read-then-increment operation is not atomic and therefore racy.

This can be avoided by using unconditionally __refcount_inc() which will
increment counter and return the old value as an atomic operation.
In case the returned counter is not one, the variable is in use and we
need to decrement counter. Otherwise we can use it.

Use __refcount_inc() instead of read and a conditional increment.

Fixes: edee4f1e9245 ("netfilter: nft_ct: add zone id set support")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Reviewed-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/netfilter/nft_ct.c